Constructor Overloading in C++

前端 未结 5 2022
慢半拍i
慢半拍i 2020-12-13 18:28

My C++ overloading does not act as I assume it should:

#include \"Node.h\"
#include 

Node::Node()
{
    cout << \"1\" << endl;
          


        
5条回答
  •  再見小時候
    2020-12-13 19:29

    The feature you're trying to use is called delegating constructors, which is part of C++0x. Using that syntax your second constructor becomes

    Node::Node(double v)
    : Node(Game(),v)
    {
        cout << "2" << endl;
    }
    

提交回复
热议问题