当我为类编写突变器时,我遇到了以下错误:
错误1:无效使用非静态数据成员'MyGraph'error2 :"MyGraph
"是'MyGraphBuilder'的私人成员 mygraphbuilder.h:51:11:注意:在这里声明为私有你能帮我解决这个问题吗!
// Header file
class MyGraphBuilder
{
private:
graph_t MyGraph;
// Mutator declared in Header, and Defined in The CPP File
void setGraph(graph_t);
}; // end of class
在 cpp 文件上定义函数
//This Part only From CPP File not From Header so I added Scope
void setGraph(graph_tYourGraph){
MyGraphBuilder::MyGraph = YourGraph;
}
// End of Part from CPP File
我很确定它应该在 cpp 文件中这样格式化
void MyGraphBuilder::setGraph(graph_t YourGraph){
MyGraph = YourGraph;
}