Declaration of virtual class template list

This is a discussion on Declaration of virtual class template list within the C++ Programming forums, part of the General Programming Boards category; Hello C-mates,
recently i rushed into the syntax of virtual funktion declaration and, unbelievabel, i declared
some pure virtual funktions ...

Declaration of virtual class template list

Hello C-mates,
recently i rushed into the syntax of virtual funktion declaration and, unbelievabel, i declared
some pure virtual funktions in a class. Besides, i declared some variables in that class too, unfortunately a list of objects of the same class... Of course the compiler complained and because of that mistake i now got a mess of unsable code.
Though all could have worked, if the class could be derived and completed, the compiler does not accept my code.
So is there a way to declare a "virtual" variable (in this case a list of virtual class objects) in a class? - I fear not, but if there are any ideas, i'm grateful for every help,
Ben

Huh? You can't change a definition of a variable to the implementation of a class.
I'm still not sure what you're trying to accomplish. Pure virtual functions are simply virtual functions that makes the class abstract (meaning you can't create an instance of it).
However, you can still derive from that class and all variables and functions that are protected and public will be visible and usable to the derived class.
Virtual functions are for polymorphism, though. Do you use that?

You can't do it that way because you are trying to use a class when it is not fully defined yet. Basically you are trying some sort of circular relationship in which one of tidyup members is a list of tidyup objects.

Meanwhile the idea of a virtual function you have is not correct. It is not merely a means to define a member function elsewhere. Virtual member functions allow these functions definitions to be altered in a derived class. A virtual member function is the means by which, for instance you can define that while a dog and a wolf are both classes derived from the class canine, the sound() member function of the wolf emits a howl and that of the dog, a bark (if you allow me the simplicity of the example).

wont compile, as you sure will apreciate.
The fact is, that there are functions in isamess, which use the variable "messies" and treat it like a normal list, as if the elements of this list were actually real class members.
Of course this is not the truth, but it makes no difference, as all uses functions are actually supposed to exist, as soon, as a subclass, which implements them is defined.
And due to the fact, that only instaces of such a subclass can be declared, the compiler would never be in the situation of not having the explicit functions given.
The matter why i want to define such a class is, that i want to derive other classes from it, while the code itself is not useable and i want prevent it from being used.

Hi Mario,
Obviously there is no problem in that circular relationship, as the list is not nescessarily filled with objects.

i appreciate to what you have said, although i think, that this is not the only aim of a virtual function, as there is no need to define a virtual fuction in a base class (in this case it gets a pure virtual function). Declaring pure virtual functions is the fulfill of the idea to provide framework, which is in the very beginning not useable as real class but as a guide that defines some standards.
Of couse souch a construction can always be replaced by a real object which can be changed afterwards, but the other way its a good possibility to arrange the code for a special goal.

Last edited by benshi; 02-02-2008 at 04:01 PM.
Reason: unclear arangement while talking about order

If isamess is an abstract class, you can't have a list of them because an isamess object is not meant to be instantiated.

Since you have virtual functions it might be more meaningful to store pointers to isamess objects. Although you cannot instantiate isamess itself, you might want to fill up the list with derived objects.