开发者

Doesn't C++ IDE Netbeans or Eclipse support class inheritance?

开发者 https://www.devze.com 2023-01-04 13:54 出处:网络
I am using NetBeans IDE 6.8 to create C++ project. While I use class inheritance, however, it seems to me that it does not recognize the derived class. Here is what I have:

I am using NetBeans IDE 6.8 to create C++ project. While I use class inheritance, however, it seems to me that it does not recognize the derived class. Here is what I have:

class A
{
public:
    A(vector<double> a, double b) {...}
};

class B : public A
{
public:
    additionalfunction(...) {...}
};

main()
{
    vector<double> c = something;
    double d = 0;
    B b=B(c, d);
}

And the compiler tells me that "B(c,d)" is not declared. I tried Eclipse C++, it told me the same thing. Why is that? Is it because both IDEs do not support C++ inh开发者_运维问答eritance? What should I do?

Any reply is appreciated.


Subclasses don't inherit constructors. You're trying to call B(double, double), but there is no B(double, double). You can define B(double, double), or you can use this pattern from the C++ FAQ.


In C++, constructors (and destructors) are not inherited like regular methods. You need to define B(vector, double). However, you can perform a sort of call on the parent constructor in the initialization list:

public:
    B(vector<double> a, double b) : A(a, b){
        ...
    }


I'd suggest implementing the constructor in class B.

0

精彩评论

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

关注公众号