+ 1
Can we add structures under class?
6 Réponses
+ 1
what do you mean by structures? and in which language?
+ 1
in c++
+ 1
I mean data structure .. can we use struct inside class as we do like in nested if?
+ 1
class Car {
private:
int nWheels;
int curbWeight;
public:
int GetNWheels() { return nWheels; }
struct Engine {
int cylinders;
int horsepower;
}
Engine engine;
}
This is perfectly valid in c++.
Car myCar;
cout << "This car's horsepower is " << myCar.engine.horsepower << endl;
It would be a good idea to define everything within the constructor function. Is this what you were looking for?
EDIT: Here is my own Playground example.
https://code.sololearn.com/crRfGrL8rmRd
+ 1
Well, what is your question then?
To take your words literally, my example was a "structure under a class", so I'm not sure what you are asking.
0
tnx but this was not my question.... although this solution was cool