+ 1
Nested Classes - NEED HELP !
i want to end up with something like transform.position.x or like pokemon.pikachu.tackle.strength or something. i just cant figure out how i cpp. can someone please help me ? googled for hours... include <iostream> using namespace std; namespace Gameobject { struct Transform { struct Position { public: int x; int y; }; }; }; int main() { Gameobject go; cout << go.Transform.Position.x << endl; return 0; }
3 odpowiedzi
+ 2
I actually found the solution. somehow i thought i needed nested classes, but i didnt:
#include <iostream>
using namespace std;
class Vector3
{
public:
int x;
int y;
int z;
};
class Transform
{
public:
Vector3 position;
Vector3 scale;
Vector3 rotation;
};
class Gameobject
{
public:
Transform transform;
};
void SetGameobject(){
Gameobject go;
go.transform.position.x = 35;
cout << go.transform.position.x << endl ;
}
int main() {
SetGameobject ();
return 0;
}
+ 1
@ivan G its cpp (c++) like i mentioned in the thread. the tag is also c# because gameobject.transform and so on is an classic c# example in unity. i wanted to do the same in cpp though
0
Can't see any c# here