c++ - const 属性的复制构造函数问题

标签 c++

class exemple{
const int a

exemple(exemplec const &item){
}

};

我需要为一个带有 const 属性的项目创建一个复制构造函数,我不知道如何创建它。

最佳答案

按照以下操作,将复制构造函数公开,修正拼写错误,复制成员的值。

class exemple
{
    const int a;
  public:    
    exemple(exemple const &item) : a(item.a) {}
};

您可以像代码一样使用初始化列表来初始化常量成员。

关于c++ - const 属性的复制构造函数问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20227272/

相关文章:

c++ - 具有替换自由方法的结构的 scoped_ptr

c++ - 十六进制到 float IEEE 754 double c++

c++ - 带有 Unicode UTF-16 (1200) 代码页字符串表的 VerQueryValue 失败

c++ - 如何在 Ubuntu 12.0.4 上安装 GCC 2.95?

c++ - 编写高效的回溯函数

c++ - CMake 错误 try_compile pthreads of type executable

c++ - 如何让cmake在msys2下使用gnu工具栈(mingw)

c++ - 嵌套结构属性继承

c++ - 使用 SpriteFont 类绘制文本时出现的问题

c++ - 如何在 Visual Studio C++ 中检查函数运行时间?