码
category::category ( const std::string p_name , std::string p_ImagePath) :
m_name { p_name },
m_ImagePath {p_ImagePath }
{
}
头
#pragma once
#include <string>
class category
{
public:
const int i;
explicit category ( const std::string p_name ,const std::string p_ImagePath);
~category ( );
std::string GetName ( );
private:
std::string m_name;
std::string m_ImagePath;
};
由于赋值操作符
,我总是得到错误Fehler 1错误C2280:&#39;预订和预订:: operator =(const booking&amp;)&#39; :尝试引用已删除的函数C:\ Program Files(x86)\ Microsoft Visual C ++编译器2013年11月CTP \ include \ utility 53
如果我尝试在类中使用const成员变量或const静态成员变量。
I tried const i = 5;
static const i = 5;
and const i; -> i gets initialized in constructor.
什么都行不通,我该如何解决这个问题? 我不能使用constexpr,因为vs2013没有帮助它:(
我已经在Stackoverflow上检查过一些问题,但一切都是用constexpr
答案 0 :(得分:2)
您必须明确定义copy assignment operator
。由于您的class
有一个constant
,non-static
数据成员,因此删除了编译器定义的copy assignment operator
。
还完全不清楚constant
定义中non-static
,class
数据成员的含义是什么。
对于constructor
,您可以删除函数说明符explicit
并将参数定义为常量引用。
category( const std::string &p_name, const std::string &p_ImagePath );