函数参数之前的类关键字是什么
What is the class keyword before a function argument?
为什么这段代码有效?看到 f
函数参数前面的 class
关键字了吗?如果我添加它,它会改变什么?
struct A
{
int i;
};
void f(class A pA) // why 'class' here?
{
cout << pA.i << endl;
}
int main()
{
A obj{7};
f(obj);
return 0;
}
如果作用域中存在名称与类类型名称相同的函数或变量,则可以在名称前面加上类以消除歧义,从而生成详细的类型说明符。
始终允许您使用详细的类型说明符。但是,它的主要用例是当您有一个具有相同名称的函数或变量时。
cppreference.com 的例子:
class T {
public:
class U;
private:
int U;
};
int main()
{
int T;
T t; // error: the local variable T is found
class T t; // OK: finds ::T, the local variable T is ignored
T::U* u; // error: lookup of T::U finds the private data member
class T::U* u; // OK: the data member is ignored
}
相关文章:
- 当我从下面的代码中删除关键字 virtual 时,它可以正常工作,否则会出现错误。在这里"virtual"字的意义是什么?
- 这个额外的关键字在这个 c++ 类声明中是什么意思?
- "friend"关键字在C++中是什么意思?
- 关键字使用的功能是什么?
- 统一初始化是隐式发生的,即使 int 强制转换运算符是使用 explicit 关键字声明的.原因是什么?
- ELI5 函数名称后面的"&&"关键字是什么意思
- 在 Objective-C++ 中应用于__weak指针时,通过关键字推导类型"auto"规则是什么?
- 内联函数 - 相对于内联关键字,它们到底是什么
- C++中"using"关键字背后的逻辑是什么?
- c++ 类访问关键字"signals"是什么意思?
- CppUTest中extern关键字的替代方案是什么
- 摩西源代码中的关键字可变是什么?
- C++中的"and"、"or"等关键字的目的是什么?
- 函数参数之前的类关键字是什么
- c++函数签名的附加关键字是什么
- MSVC 中"interface"关键字是什么?
- 使用' operator '关键字是什么意思?
- 在Win-32 c++应用程序中CALLBACK关键字是什么意思?
- 当重写一个方法时,虚拟关键字是什么意思
- 在c++代码中,以下关键字是什么意思?SIGSELECT,U32,U16,U8