开发者

base c'tor with derived argument

I created some class:

class Base{
public:
 Base(int = 0);
 ~Base();
 Base(Base&);
 Base(Derived&); //<- here
 int valueOfBase();
protected:
 int protectedData;
private:
 int baseData;
};

class Derived: public Base{
public:
    Derived(int = 0);
    Derived(Derived&);开发者_JS百科
    ~Derived();
private:
    int derivedData;
};

###//Impplementation in .cpp

Base::Base(Base& base)
{
    baseData = base.baseData;
    protectedData = base.protectedData;
    cout << "base Copy C'tor" << endl;
}

Base::Base(Derived& hello)
{
    baseData = hello.protectedData;
}

but when I try to compile some code I receive an erro (near here)

expected ) before & token

can I create base c'tor with derived argument for writing somethin like that

Derived derived(1);
Base base1 = derived;

if no why? thanks in advance


You probably need a forward declaration of Derived.

Try adding class Derived; above your Base class definition.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜