我正在使用ROOT frameowrk,我想写一个有TMultiGraph
成员的类。我试图为我的班级编写和分配操作符但是由于compilaton问题我失败了。课程TMultiGraph
将其作为protected
的作业运算符保留。
我班级的标题:
#include "../include/clipper.hpp"
#include "TMultiGraph.h"
#include "TColor.h"
#include "RtypesCore.h"
using namespace ClipperLib;
class ClipperDraw : protected TMultiGraph {
public:
ClipperDraw() {}
ClipperDraw& operator=(const ClipperDraw &c);
private:
TMultiGraph mg;
};
.cpp
是:
ClipperDraw& ClipperDraw::operator=(const ClipperDraw &c)
{
mg = c.mg;
return *this;
}
编译时我收到此消息:
g++ -fPIC -Wall `root-config --cflags` -I./include -O2 -c -o obj/ClipperDraw.o src/ClipperDraw.cpp
In file included from src/../include/ClipperDraw.h:12:0,
from src/ClipperDraw.cpp:8:
/home/user/anaconda3/envs/deepjetLinux3/include/TMultiGraph.h: In member function ‘ClipperDraw& ClipperDraw::operator=(const ClipperDraw&)’:
/home/user/anaconda3/envs/deepjetLinux3/include/TMultiGraph.h:47:17: error: ‘TMultiGraph& TMultiGraph::operator=(const TMultiGraph&)’ is protected
TMultiGraph& operator=(const TMultiGraph&);
^
src/ClipperDraw.cpp:26:5: error: within this context
mg = c.mg;
^
Makefile:19: recipe for target 'obj/ClipperDraw.o' failed
make: *** [obj/ClipperDraw.o] Error 1
答案 0 :(得分:1)
TMultiGraph
的复制构造函数和复制赋值运算符都标记为受保护。这意味着您无法将TMultiGraph
分配给其他TMultiGraph
。继承对你没有帮助,因为它不会改变这个事实。
从TMultiGraph
继承的内容是允许创建自己可以复制的图表类。那看起来像是
class MyMultiGraph : public TMultiGraph {
//...
public:
MyMultiGraph& operator =(const MyMultiGraph& rhs)
{
TMultiGraph::operator=(rhs);
// assign MyMultiGraph member here
}
};