class Base {
public:
virtual Base* NewSelf() { return NULL; }
Base* Copy() {
Base *out=NewSelf(); //How can I call the higher up functions of 'NewSelf()' here?
if (out==NULL) return out;
*out=this;
return out;
}
};
class SubA : public Base {
public:
Base* NewSelf() { return new SubA; }
};
class SubB : public Base {
public:
Base* NewSelf() { return new SubB; }
};
More C++ Polymorphism - Calling A Function Up a Hiearchy...
Is there some way to call the highest function up in a C++ polymorphic hierarchy? Example:
[Please note that this isn't exactly what I'm trying to do, but it's close]
Well, as I was typing this, I though of something: Would "this->NewSelf()" call the higher functions? It seems like that would make sense, but I don't know... [Goes to test it]
Don't say it... Please, don't say it.
I know this was a retarded question. I had forgotten that when a class executes it's virtual functions, it executes them at the highest scope, and that you have to use scoping to call the LOWER functions, not the HIGHER ones.
I know this was a retarded question. I had forgotten that when a class executes it's virtual functions, it executes them at the highest scope, and that you have to use scoping to call the LOWER functions, not the HIGHER ones.
If the base had access to the derrived type and could then upcast the 'this' pointer to the derrived type you might be able to access its methods.
Just a thought and probably wrong.
ace
Just a thought and probably wrong.
ace
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement