struct in class

前端 未结 6 1164
梦毁少年i
梦毁少年i 2020-12-30 05:09

I have struct in class and not know how to call variables from struct, please help ;)

#include 
using namespace std;

class E
{
public: 
            


        
6条回答
  •  庸人自扰
    2020-12-30 05:53

    Your E class doesn't have a member of type struct X, you've just defined a nested struct X in there (i.e. you've defined a new type).

    Try:

    #include 
    
    class E
    {
        public: 
        struct X { int v; };
        X x; // an instance of `struct X`
    };
    
    int main(){
    
        E object;
        object.x.v = 1;
    
        return 0;
    }
    

提交回复
热议问题