在c++中是否可以在代码体中声明一个属性?
Is it possible in C++ to declare an attibute in the body?
在c++中是否可以在主体(即.cpp文件)中声明属性?
如果您所说的attribute
是指类的member variable
,那么答案是:"成员变量必须在类定义中定义。"它们不能在其他任何地方定义,既不能在构造函数中定义,也不能在任何成员函数中定义。
类定义是在头文件中还是在源文件(.cpp)中都不重要。
你不能在类的原始定义之外添加属性(通常在头文件中),例如在.cpp
文件中
是:
test.cpp:
class Test
{
int x; //declare attribute in class body and in cpp file
};
相关文章:
- 如何通过一个循环将多个文件的内容分配给不同的类属性?
- 如何使用指针从另一个类访问属性
- 是否可以在 c++ 中创建一个文件并为其提供属性以将其隐藏?(在 Ubuntu 上)
- 给一个图 G 找到此图中的所有节点 blob,以便 node.color 属性 = 特定颜色
- 让 Redhawk 组件访问另一个组件的属性
- 我有一个嵌套数组,它由另一个数组中的元素组成,这些元素分组为2.之后,我想显示每个元素的属性
- 如何在一个属性中动态存储基元类型
- 我应该使用多个角色还是一个角色,将实际属性推迟到将数据包装/公开为其属性的QObject
- 使用 QGenericMatrix 作为另一个类的属性
- 为什么要为一个属性指定不同的顶点格式
- QList 作为 qt 设计器自定义小部件中的一个属性
- 在子类中定义一个属性,然后在父类中使用它,这在PHP中是一种奇怪的行为
- 从VCL向C++公开delphi中的一个属性
- 提升因果报应-从一个属性生成多个字符串
- 我们可以为一个类指定一个属性名称吗?即使该属性是另一个表中的列
- 为什么我需要这个指针作为一个属性
- 在c++中是否可以在代码体中声明一个属性?
- 构造对象,其中一个属性依赖于另一个属性.在C++中
- 如何在现有的json11对象(c++)上附加一个属性值对
- 一个属性用于不同的类型