0

I have a class named "package" which is the base of the derived "shader_package".

The package instances generally get exclusively generated in a function called load. It has a pointer to package as a return parameter. Therefore I can also return every class derived from package due to inheritance. However, when passed the type information is lost (correct?) and I cant actually know anymore afterwards what the original class was.

In my case, however, this shouldnt be a problem. The stuff returned by the loader is supposed to be used in a class constructor or assignment operator, that then uses the info in the correlating package derivertive to initialize its member variables.

How can I do this properly, without having to use a union or variant type?

EDIT:

Some pseudo code illustrating what I want to accomplish

class package{
//actual contents are not relevant. The base doesnt have any virtual functions. Only data
}
.
class shader_package:public package{
private:
    shaderData data;
public:
//getters setters and other standard stuff. Not really relevant
}
.
.
package* import(const char* path){
    string extension = getExtension(path);
    if(extension == ".shader"){
        shaderData data;
        //somehow populate shaderData
        return new shader_package(shaderData);
    }
    /* Check for other types and return other derived packages*/
}
.
.
.
main{
    shader nShader(import("pathToShader"));
    /*Do stuff with it*/
}
MoustacheSpy
  • 743
  • 1
  • 6
  • 27

0 Answers0