我为类的私有对象成员编码mutator时出错(称为MyGraph的图)

问题描述 投票:0回答:1

当我尝试为MyGraphBuilder Class编写一个Mutator时,我得到以下Errors错误1:无效使用非静态数据成员'MyGraph']error2:“ MyGraph”是“ MyGraphBuilder”的私有成员mygraphbuilder.h:51:11:注意:在此声明为私有您能帮我解决这个问题吗!

using namespace boost;
using namespace std;
typedef adjacency_list < vecS, vecS, directedS, property < vertex_name_t, idType >, property < edge_weight_t, double > > graph_t;

class MyGraphBuilder
{
 private:
  graph_t MyGraph;

// Mutator declared in Header, and Defined in The CPP File
void setGraph(graph_t);
//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 , The Rest From Header
}; // end of class
c++ boost graph boost-graph
1个回答
0
投票

我很确定它应该在cpp文件中像这样格式化

void MyGraphBuilder::setGraph(graph_t YourGraph){
    MyGraph = YourGraph;
}
© www.soinside.com 2019 - 2024. All rights reserved.