Creating a object depending on the content of a pointer?
2 replies, posted
If I wanted to do something like this:
[php]
Class Function()
{
Class class;
Class class_2;
class_2 = new class;
return class_2;
}[/php]
what would be the proper way to? I've already tried searching "Factory C++", which is what I'm trying to make. Is there any way to do this?
No.
[editline]09:56PM[/editline]
The simplest factory is something like so:
[code]
class base { ... };
class foo : public base { ... };
class bar : public base { ... };
base *create(const string &type)
{
if (type == "foo") return new foo();
else if (type == "bar") return new bar();
...
return NULL;
}
int main()
{
base *guy = create("foo");
}
[/code]
Oh, ok thanks.
Sorry, you need to Log In to post a reply to this thread.