指向成员成员的指针 [英] pointer to a member of a member
问题描述
说我有两节课:
A级
{
公开:
int x;
};
class B
{
public:
A a;
};
然后我如何构建一个指向B :: ax的成员指针?什么是语法
呢?
谢谢!
Say I have two classes:
class A
{
public:
int x;
};
class B
{
public:
A a;
};
Then how do I construct a member pointer to B::a.x ? What''s the syntax
for it?
Thanks!
推荐答案
hu ***** @ gmail.com 写道:
Say我有两节课:
A级
{
public:
int x; < br $>
};
B级
{
公开:
A;
};
然后如何构造一个指向B :: ax的成员指针?什么是语法
呢?
Say I have two classes:
class A
{
public:
int x;
};
class B
{
public:
A a;
};
Then how do I construct a member pointer to B::a.x ? What''s the syntax
for it?
为什么你认为你需要它?这有用吗:
B b;
int * ptr =& bax;
V
-
请在通过电子邮件回复时删除资金''A'
我不回复热门回复,请不要问
Why do you think you need it? Does this help:
B b;
int *ptr = &b.a.x;
V
--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask
hu ***** @ gmail.com 写道:
说我有两节课:
A级
{
公开:
int x;
};
B级
{
public:
A a;
};
那怎么办我构造了一个指向B :: ax的成员指针?什么是语法
呢?
谢谢!
Say I have two classes:
class A
{
public:
int x;
};
class B
{
public:
A a;
};
Then how do I construct a member pointer to B::a.x ? What''s the syntax
for it?
Thanks!
不确定您需要什么,但下面的代码示例可能有所帮助
int A :: * ptr = A :: x;
例子;
示例。* ptr = 15;
JB
Not sure what you require, but the code sample below may be of help
int A::*ptr = A::x;
A Example;
Example.*ptr = 15;
JB
n2xssvv.g02gfr12930写道:
n2xssvv.g02gfr12930 wrote:
hu **** *@gmail.com 写道:
>说我有两个班级:
A班级
{
公开:
int x;
};
B班
{
公开:
A a;
};
然后如何构造一个指向B :: ax的成员指针?它的语法是什么?
谢谢!
>Say I have two classes:
class A
{
public:
int x;
};
class B
{
public:
A a;
};
Then how do I construct a member pointer to B::a.x ? What''s the syntax
for it?
Thanks!
不确定您需要什么,但下面的代码示例可能有所帮助
int A :: * ptr =斧头;
Not sure what you require, but the code sample below may be of help
int A::*ptr = A::x;
int A :: * ptr =& A :: x;
(没有&符号''不合法的。
int A::*ptr = &A::x;
(without the ampersand it''s not legal).
一个例子;
例子。* ptr = 15;
A Example;
Example.*ptr = 15;
现在为B做这个...... :-)
V
-
请在通过电子邮件回复时删除资金''A'
我没有回复最热门的回复,请不要''请问
Now do that for a ''B''... :-)
V
--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask
这篇关于指向成员成员的指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!