#include "..\Objects\Objects.h"
class Idle;
class Activity
{
public:
Objects *Actor;
Goods *Target;
Objects and Goods are both abstract.
How can I declare an abstract object inside another class?
Thanks
Jack
#include "..\Objects\Objects.h"
class Idle;
class Activity
{
public:
Objects *Actor;
Goods *Target;
Objects and Goods are both abstract.
How can I declare an abstract object inside another class?
Thanks
Jack
class a
{
public:
class b
{
public:
virtual void something() = 0;
}
}
[\code]
Not sure why you would want to do this.
You want to do that to make that class only accessible form that class usually, this is what a PIMPL implementation often uses, you should avoid pimpl it's a bad pattern. You shouldn't be hiding the data a class is operating on.
You can instantiate a pointer to an abstract class by newing an object instance of a derived class on it.
class base:
{
virtual void abstractMethod() = 0;
}
class derived : public base
{
virtual void abstractMethod()
{
cout << "fubar" << endl;
}
}
void main()
{
Base* derivedInstance = new derived();
derivedInstance->abstractMethod();
delete derived;
}
Say what? This is the exact opposite of the advice I would give if I were to give good advice.You want to do that to make that class only accessible form that class usually, this is what a PIMPL implementation often uses, you should avoid pimpl it's a bad pattern. You shouldn't be hiding the data a class is operating on.
How can I declare an abstract object inside another class?
I'm not sure what you're trying to ask here. Do you mean how do you instantiate objects of a concrete class derived from an abstract class? Google for 'factory function'.
You cannot produce an 'abstract object' at all, abstract classes are used for inheritance, as interface for a concrete class derived from it.
If Object and Goods are in fact not abstract, just use 'Target = new Goods()' and 'Actor = new Objects()' into the constructor or something if thats what you want (although I would probably just use static objects by deleting the asterisk if thats your plan).
You want to do that to make that class only accessible form that class usually, this is what a PIMPL implementation often uses, you should avoid pimpl it's a bad pattern. You shouldn't be hiding the data a class is operating on.