Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/154.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 正确实例化双重继承对象?_C++_Inheritance - Fatal编程技术网

C++ 正确实例化双重继承对象?

C++ 正确实例化双重继承对象?,c++,inheritance,C++,Inheritance,我试图使用双重继承,将一个更复杂的对象声明为两个简单对象的总和。但是,当我尝试按如下方式进行操作时: class common_cfullr { public: double core; double thr; double thrres; common_cfullr(double Core, double Thr, double Thrres){ core=Core; thr=Thr; thrres=Thrres; }; ~common_cful

我试图使用双重继承,将一个更复杂的对象声明为两个简单对象的总和。但是,当我尝试按如下方式进行操作时:

class common_cfullr
{
public:
  double core;
  double thr;
  double thrres;
  common_cfullr(double Core, double Thr, double Thrres){
    core=Core;
    thr=Thr;
    thrres=Thrres;
  };
  ~common_cfullr(){};
  common_cfullr() :
    core(0.0),
    thr(0.0),
    thrres(0.0)
  {}
};

class common_cfull
{
 public:
  int nelec;
  int ms2;

  common_cfull (int  Nelec,
  int  Ms2){
    nelec      =Nelec;  
    ms2        =Ms2;    
   };
  ~common_cfull(){};
  common_cfull() :
    nelec(0),
    ms2(0){}
};

///Structure inheritance
class  common :
  public common_cfullr,
  public common_cfull
{public:
  common(){};
  ~common(){};
};

int main(int argc, char** argv)
{
  common cmn();
  cmn.nelec=0;

  return 0;
}
我从编译器那里得到一个错误。为此,如何正确使用双重继承

任何建议都将不胜感激。

(基于Neik Kirk的评论)更改
通用cmn()
普通cmn使您的代码编译时不会出错

使用
clang++
进行编译时,编译器发出的注释也会告诉您:

t.cc:48:13: warning: empty parentheses interpreted as a function declaration
      [-Wvexing-parse]
  common cmn();
            ^~
t.cc:48:13: note: remove parentheses to declare a variable
  common cmn();
            ^~

如果你有一个错误,它会很高兴你分享它说的<代码>公共cmn()这是最烦人的解析(谷歌it)。您必须使用
通用cmn它实际上不是最麻烦的解析,但它是相关的。这是一个常见的误解。非常感谢您的帮助!