struct in class

前端 未结 6 1131
梦毁少年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 06:00

    You should define the struct out of the class like this:

    #include 
    using namespace std;
    struct X
    {
            int v;
    };
    class E
    {
    public: 
          X var;
    };
    
    int main(){
    
    E object;
    object.var.v=10; 
    
    return 0;
    }
    

提交回复
热议问题