Hello all,
I am writing a base class that will be inherited by other classes. However, I do not want this class to be instantiated directly. I only want it to be inherited from. Is this possible?
Thanks, dene.
Hello all,
I am writing a base class that will be inherited by other classes. However, I do not want this class to be instantiated directly. I only want it to be inherited from. Is this possible?
Thanks, dene.
Be a leader and not a follower.
Yes there is use something like the following code segment.
Code:virtual class MyClass { public: int get_data(); virtual void my_function(); private: int data; };
"Computer Science is no more about computers than astronomy is about telescopes"
- E.W. Dijkstra
http://msdn.microsoft.com/library/de...m/deriv_15.asp
Although you could still have pointers or references to a class object
"Think not but that I know these things; or think
I know them not: not therefore am I short
Of knowing what I ought."
-John Milton, Paradise Regained (1671)
"Work hard and it might happen."
-XSquared
"Although you could still have pointers or references to a class object". Does this mean that I can still do: MyClass *t = new MyClass()?
Be a leader and not a follower.
No...First of all it would be:
MyClass* T = new MyClass
and second, you could not do it anyway
"Think not but that I know these things; or think
I know them not: not therefore am I short
Of knowing what I ought."
-John Milton, Paradise Regained (1671)
"Work hard and it might happen."
-XSquared
Ok, thanks for everyones help.
Be a leader and not a follower.
virtual class ..
???
I doubt that's allowed in C++. Abstract classes have at least one pure virtual method:
virtual void pure() = 0;
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
>I doubt that's allowed in C++.
It isn't. But it could just be a new feature recently added to the language by the extensions committee. You know how much they love adding new features.
My best code is written with the delete key.
The pointers you can use like this:
And if you want a class that should be an abstract data type, but none of the member functions lend themselves to being pure virtual, you can have a pure virtual destructor.Code:class A { virtual void foo( ) = 0; }; class B : public A { void foo( ) { } }; // Somewhere else... A* obj = new B; // ... = new B( ); would also work, though
You could make the constructor protected.
Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling
Nope, I don't think it's a new feature its a typo sometimes I break into an accidental Java type code except in Java the class is preceeded with the keyword abstract. Thanks for catching that CornedBee!
"Computer Science is no more about computers than astronomy is about telescopes"
- E.W. Dijkstra
True... But it is still possible to instantiate it (static builder function, for example). Granted, the particular application will determine if this makes sense or not in the context of the program.Originally Posted by Sang-drax