指向派生类C ++的指针

时间:2014-04-11 13:54:03

标签: class pointers derived

我在导出派生类的指针时遇到了一些麻烦。我认为它与构造函数有关。我是否必须在派生类中创建新的构造函数?如何从派生类创建指针?感谢

 Class Base
 {
   public:



   int myfunction(int a,int b,int c)
   {
   return a+b+c;
   }
 };

 Class Derived: public Base
{
  int newfunction(int a, int b, int c)
  {
   return a*b*c;
  };

};


int main()
{
// this doesn't work at all.. I get all errors every time I try to refer to the object
//instantiated from my derived class.
//I know it's my lack of understanding.


Derived *NewObject = new Derived;

//Why wont this work?


 }

1 个答案:

答案 0 :(得分:0)

C ++区分大小写,关键字class为小写。您为这两个类编写了Class,看起来它是您代码的唯一问题。