简体   繁体   English

C ++ IDE Netbeans或Eclipse不支持类继承吗?

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

I am using NetBeans IDE 6.8 to create C++ project. 我使用NetBeans IDE 6.8来创建C ++项目。 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. 编译器告诉我“B(c,d)”没有声明。 I tried Eclipse C++, it told me the same thing. 我试过Eclipse C ++,它告诉我同样的事情。 Why is that? 这是为什么? Is it because both IDEs do not support C++ inheritance? 是因为两个IDE都不支持C ++继承吗? 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). 你试图调用B(double,double),但没有B(double,double)。 You can define B(double, double), or you can use this pattern from the C++ FAQ. 您可以定义B(double,double),也可以使用C ++ FAQ中的此模式

In C++, constructors (and destructors) are not inherited like regular methods. 在C ++中,构造函数(和析构函数)不像常规方法那样继承。 You need to define B(vector, double). 你需要定义B(矢量,双精度)。 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){
        ...
    }

我建议在B类中实现构造函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM