如何将typedef变量赋值为静态
how to assign typedef variables as static
谁能告诉我下面程序中的错误?
#include <iostream>
using namespace std;
class A
{
public:
typedef int count;
static count cnt ;
};
count A::cnt = 0;
int main()
{
return 0;
}
错误count没有指定类型
您必须使用A::count A::cnt = 0;
,因为您的typedef是在类a的范围内定义的。
。要么将类型定义移出类,要么如上所述使用范围解析。
您的typedef
在您的类中,因此不是全局可用的。
你需要
#include <iostream>
using namespace std;
typedef int count;
class A
{
public:
static count cnt ;
};
count A::cnt = 0;
int main()
{
return 0;
}
相关文章:
- 如果类在 C++ 中具有常量或引用类型的非静态数据成员,为什么编译器不提供默认赋值运算符?
- 静态成员函数赋值而不带返回语句
- 是否应该在复制构造函数或赋值运算符中复制静态数据成员
- 为什么静态修饰符会阻止其变量重新赋值
- 我们不能在未赋值的上下文中命名非静态成员函数是有原因的吗
- 为类中的私有静态变量赋值
- 错误:非静态引用成员"std::ostream&Student::out",无法使用默认赋值运算符
- 存在静态常量成员时的赋值运算符
- 错误:非静态引用成员,无法使用默认赋值运算符
- 了解工厂方法和静态变量赋值的返回值优化 (Visual Studio)
- C++ 将静态 int 的值赋值分配给 int
- C++类中的静态数组赋值
- 在C++03中,在未赋值的上下文中使用表示非静态数据成员的id表达式有效吗
- visual如何在托管C++类中为静态变量赋值
- 这个静态变量赋值给局部函数中的指针有什么问题
- 初始化中的静态赋值
- 如何将typedef变量赋值为静态
- 在静态数组中不使用重载赋值和复制构造函数的原因
- 不能在const成员函数中赋值给非静态数据成员
- 静态成员变量赋值