E
Erdal Mutlu
Hi,
I am trying to design a base class (interface) with two or more subclasses
as follows:
class A {
....
virtual static A* getByName(const string x)=0 const;
}
class B : public A {
....
virtual static A* getByName(string x) const;
}
class C : public A {
....
virtual static A* getByName(string x) const;
}
....
void doSomething(const A* a);
The getByName() member function is a utility function, which creates a
pointer to an object of type A. The B and C classes are going to be used
at the beggining, when they are created, afterwards I would like to use the
base class (A) as arguments to functions. Is there a way of doing this, but
without returning a pointer to an A object? The problem is that care must be
taken for deleting pointers at some point. I would like to use
constructor/destructor do the job of creating and auto deleting of objects.
If I return an A object, then the B or C part of the object is going to be
sliced off.
Best regards.
Erdal Mutlu
I am trying to design a base class (interface) with two or more subclasses
as follows:
class A {
....
virtual static A* getByName(const string x)=0 const;
}
class B : public A {
....
virtual static A* getByName(string x) const;
}
class C : public A {
....
virtual static A* getByName(string x) const;
}
....
void doSomething(const A* a);
The getByName() member function is a utility function, which creates a
pointer to an object of type A. The B and C classes are going to be used
at the beggining, when they are created, afterwards I would like to use the
base class (A) as arguments to functions. Is there a way of doing this, but
without returning a pointer to an A object? The problem is that care must be
taken for deleting pointers at some point. I would like to use
constructor/destructor do the job of creating and auto deleting of objects.
If I return an A object, then the B or C part of the object is going to be
sliced off.
Best regards.
Erdal Mutlu