2017-02-28 14 views
0

クラスの中には、パラメータを持つMeshクラスのインスタンスを返す関数があります。このクラスではメッシュは、パラメータを持つコンストラクタ、およびいくつかの公共のフィールドがあります。宣言されたクラスのデータに直接アクセスします。

class Model 
{ 
public: 
    Model(string path) 
    { 
     this->loadModel(path); 
    } 

    Mesh loadModel(string path) 
    { 
     vector<GLfloat> vertices; 
     vector<GLuint> indices; 
     ... 
     return Mesh (vertices, indices); 
    } 
}; 
class Mesh 
{ 
public: 
    vector<GLfloat> vertices; 
    vector<GLuint> indices; 

    Mesh(vector<GLfloat> vertices, vector<GLuint> indices) 
    { 
     this->vertices = vertices; 
     this->indices = indices; 
     this->loadMesh(); 
    } 

    void loadMesh() 
    { 
     //sending data to OpenGL 
    } 
}; 

int main() 
{ 
    Model model("folder/..."); 
    return 0; 
} 

主な機能では、我々は唯一のモデルクラスを宣言します。 Meshクラスはその場で作成され、OpenGLにデータを送信します。 main関数内のクラスMesh(verticies、indicies)のフィールドにどのようにアクセスできますか?またはそれはもはや存在しないのですか?ありがとうございました!

答えて

0

Model::loadModelは、Meshオブジェクトを返します。

this->loadModel(path); 

戻り値は何もしません。返されたオブジェクトが破棄されると、その情報は失われます。

関連する問題