I want to have a derived class with a custom constructor. What I am trying is this:
But unfortunately I seem to only be allowed to do this:Code:class Base { protected: int Number; int MaxMemory; Base(int inNumber,int inMaxMemory); }; class Leaf : public Base { protected: void *ExtraData; Leaf(int inNumber,int inMaxMemory) : Base(inNumber,inMaxMemory); // putting the semicolon here gives an error (It says that I should put "{") }; Leaf::Leaf(int inNumber,int inMaxMemory) : Base(inNumber,inMaxMemory) { ExtraData = malloc(100); // Do some extra initalization of members }
So I can call the proper inherrited constructor with the proper arguments, but I can't do any further initialization of any extra members in the class. How to solve this?Code:class Leaf : public Base { protected: void *ExtraData; Leaf(int inNumber,int inMaxMemory) : Base(inNumber,inMaxMemory){} };



LinkBack URL
About LinkBacks



CornedBee