Answer the question
In order to leave comments, you need to log in
Why does the size of the object not match?
I have a class:
class object {
private:
public:
vector<vector<double>> coords;
vector<vector<int>> rels;
};
class Terrain : public object {
private:
public:
vector<vector<double>> coords = { {-viewportrl,viewportrl,0},{viewportrl,viewportrl,0},{-viewportrl,-viewportrl,0},{viewportrl,-viewportrl,0} };
vector<vector<int>> rels = { {2,3},{1,4},{1,4},{2,3} };
};
Terrain terr;
vector<object> wld = { terr };
Answer the question
In order to leave comments, you need to log in
1) You should not allow sticking out of data field classes - all fields, except perhaps constants, should be made private.
2) In this case, your classes will have methods for accessing these fields, which will need to be declared virtual
3) Instead of storing instances in a vector of objects, you should make a vector of smart pointers to these objects
4) It is desirable to make the base class for these objects abstract , at worst - interface.
After that, your homologous class hierarchy will behave the way you want it to.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question