views:

100

answers:

3

Hi, 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++ inheritance? What should I do?

Any reply is appreciated.

+1  A: 

I'd suggest implementing the constructor in class B.

Christian
Thanks. Got it.
Ellen
+4  A: 

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.

Dave
I see. Thanks. That helps a lot.
Ellen
+4  A: 

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){
        ...
    }
tlayton
Thanks. That works.
Ellen