在类中的struct [英] struct in class

查看:147
本文介绍了在类中的struct的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在类中有struct,不知道如何从struct调用变量,请帮助;)

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

#include <iostream>
using namespace std;

class E
{
public: 
    struct X
    {
        int v;
    };
};

int main(){

E object;
object.v=10; //not work 

return 0;
}


推荐答案

> 类A 并不意味着类A 的实例自动具有属性 struct B 作为成员,也不意味着它自动具有作为成员的 struct B 的实例。

I declared class B inside class A, how do I access it?

Just because you declare your struct B inside class A does not mean that an instance of class A automatically has the properties of struct B as members, nor does it mean that it automatically has an instance of struct B as a member.

除了范围界定,两个类( A B )之间没有真正的关系。

There is no true relation between the two classes (A and B), besides scoping.

struct A { 
  struct B { 
    int v;
  };  

  B inner_object;
};

int
main (int argc, char *argv[]) {
  A object;
    object.inner_object.v = 123;
}

这篇关于在类中的struct的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆