ambuli
asked on
Returning a concrete class via abstract class API
Hi there,
I have to return a concrete class instance through a abstract class function.
I have the code as given below. I want to associate the returnConcrete( ) function with the
IAbstract class somehow... I am not sure if this is possible.
I want to be able to use it in Test.cpp something like
IAbstract * c = IAbstract::returnConcrete( )
Is it possible?
Thanks,
I have to return a concrete class instance through a abstract class function.
I have the code as given below. I want to associate the returnConcrete( ) function with the
IAbstract class somehow... I am not sure if this is possible.
I want to be able to use it in Test.cpp something like
IAbstract * c = IAbstract::returnConcrete(
Is it possible?
Thanks,
1:
In IAbstract.h
--------------------
class IAbstract
{
public:
virtual void somePureVirtualFunc() = 0;
};
IAbstarct * returnConcrete(); <----
In Concrete.h
-----------------
class Concrete : public IAbstrct
{
};
Test.cpp
--------
IAbsract * c = returnConcrete();
ASKER
Thanks JKR. yes, that is how I have it. But, I am thinking that the returnConcrete( ) function when used in Test.cpp should have a scope( what I mean is it appears returnConcrete( ) is a global function when doing it this way. I want to know if it is possible to have a static method in the IAbstract class itself to return the concrete class instance.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you.
Open in new window