473,473 Members | 1,837 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

A simple qustion about C++ syntax

if A and B are Class type, what's mean about the next sentence?

" int A::*B::*pMember; "

And how to use this pointer ?

we assume A and B's definition is:
class A
{
int a;
};
class
{
B obj;
};

Mar 2 '06 #1
8 1669
Yong W wrote:
if A and B are Class type, what's mean about the next sentence?

" int A::*B::*pMember; "

And how to use this pointer ?

we assume A and B's definition is:
class A
{
int a;
};
class
{
B obj;
};


What you wrote above makes no sense - is this below what you meant to
write ?

struct A
{

struct B
{
int a;
};

B obj;
};
int A::B::* pMember;
Mar 2 '06 #2
Sorry, I have a mistake. the class A and B's definition is:

class B
{
int b;
};

class A
{
B obj;
};

Mar 2 '06 #3

Yong W wrote:
Sorry, I have a mistake. the class A and B's definition is:

class B
{
int b;
};

class A
{
B obj;
};


Thanks for posting the correct code. You are giving the full scope for
member 'b' when accessing it.
Assuming you have the pubic access specifier. If you need to give full
scope for member B you would give - A::B.
Now if you need to access 'b' you would further use the scope
resolution to get :

A::B::b

(pay special care to upper and lower case Bs)

Mar 2 '06 #4
Jaspreet wrote:
Yong W wrote:
Sorry, I have a mistake. the class A and B's definition is:

class B
{
int b;
};

class A
{
B obj;
};


Thanks for posting the correct code. You are giving the full scope for
member 'b' when accessing it.
Assuming you have the pubic access specifier. If you need to give full
scope for member B you would give - A::B.
Now if you need to access 'b' you would further use the scope
resolution to get :

A::B::b


That doesnot work because it is completely incorrect. When you say A::B
, you mean that B is a subclass inside A, and not that an instance of B
is a member of A. Saying A::B::b means that you are talking about a
static member b from a class B which is nested inside A. Something like
this :

class A
{
public:
class B
{
public:
static int b;
};
};

The Code that OP posted was much different than this. ::B::b doesnot
make any sense in the context of OP's post.

Mar 2 '06 #5
Jaspreet wrote:
Yong W wrote:
Sorry, I have a mistake. the class A and B's definition is:

class B
{
int b;
};

class A
{
B obj;
};


Thanks for posting the correct code. You are giving the full scope for
member 'b' when accessing it.
Assuming you have the pubic access specifier. If you need to give full
scope for member B you would give - A::B.
Now if you need to access 'b' you would further use the scope
resolution to get :

A::B::b


That doesnot work because it is completely incorrect. When you say A::B
, you mean that B is a subclass inside A, and not that an instance of B
is a member of A. Saying A::B::b means that you are talking about a
static member b from a class B which is nested inside A. Something like
this :

class A
{
public:
class B
{
public:
static int b;
};
};

The Code that OP posted was much different than this. A::B::b doesnot
make any sense in the context of OP's post.

Mar 2 '06 #6
Jaspreet wrote:
Yong W wrote:
Sorry, I have a mistake. the class A and B's definition is:

class B
{
int b;
};

class A
{
B obj;
};


Thanks for posting the correct code. You are giving the full scope for
member 'b' when accessing it.
Assuming you have the pubic access specifier. If you need to give full
scope for member B you would give - A::B.
Now if you need to access 'b' you would further use the scope
resolution to get :

A::B::b

(pay special care to upper and lower case Bs)


This again makes no sense. 'B' is not declared in 'A's scope, so you
cannot write 'A::B'. You can write 'A::obj', possibly. You can write
B A::*. From the latter you can try writing

int A::*B::*p;

which declares a pointer to an int member of 'B' that is a member of 'A'.
Problem is, I have no idea how to initialise it. I don't see any syntax
for that.

V
--
Please remove capital As from my address when replying by mail
Mar 2 '06 #7

Neelesh Bodas wrote:
Jaspreet wrote:
Yong W wrote:
Sorry, I have a mistake. the class A and B's definition is:

class B
{
int b;
};

class A
{
B obj;
};


Thanks for posting the correct code. You are giving the full scope for
member 'b' when accessing it.
Assuming you have the pubic access specifier. If you need to give full
scope for member B you would give - A::B.
Now if you need to access 'b' you would further use the scope
resolution to get :

A::B::b


That doesnot work because it is completely incorrect. When you say A::B
, you mean that B is a subclass inside A, and not that an instance of B
is a member of A. Saying A::B::b means that you are talking about a
static member b from a class B which is nested inside A. Something like
this :

class A
{
public:
class B
{
public:
static int b;
};
};

The Code that OP posted was much different than this. A::B::b doesnot
make any sense in the context of OP's post.


Not neccesary. You could have a containership like below.

A and B are declared like below :

class B
{
public:
static int b;
};

class A
{
public:
B bObj;
};

If you need to access static member b from B, you would probably write
B::b.
Now if you need to access that static member b from A, you would
probably write A::B::b.

Mar 2 '06 #8
Victor Bazarov wrote:
Jaspreet wrote:
Yong W wrote:
Sorry, I have a mistake. the class A and B's definition is:

class B
{
int b;
};

class A
{
B obj;
};


Thanks for posting the correct code. You are giving the full scope for
member 'b' when accessing it.
Assuming you have the pubic access specifier. If you need to give full
scope for member B you would give - A::B.
Now if you need to access 'b' you would further use the scope
resolution to get :

A::B::b

(pay special care to upper and lower case Bs)


This again makes no sense. 'B' is not declared in 'A's scope, so you
cannot write 'A::B'. You can write 'A::obj', possibly. You can write
B A::*. From the latter you can try writing

int A::*B::*p;

which declares a pointer to an int member of 'B' that is a member of 'A'.
Problem is, I have no idea how to initialise it. I don't see any syntax
for that.

V


I believe the expression is a member pointer in B that points to a
member pointer in A. Like so:

struct A
{
int i;
};

struct B
{
int A::*p1;
};

int main()
{
// this is slightly nuts:

int A::*B::*p = &B::p1;
}

Greg

Mar 2 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: martin | last post by:
Hello, I just got the SUN Java IDE. (Netbeans IDE 3.5.1) Very very nice, and I worked myself through the tutorial (about making a colorswitch). Now, When I compile it gives no errors at all. So...
27
by: Brian Sabbey | last post by:
Here is a first draft of a PEP for thunks. Please let me know what you think. If there is a positive response, I will create a real PEP. I made a patch that implements thunks as described here....
2
by: Trimbitas Sorin | last post by:
Hello I have a simple syntax question : What does the following line mean: 1: %checkType; ?? I know that @test="" is an array and $test="" is a simple variable. Thank you With best regards...
9
by: Valerio Daelli | last post by:
Hello everybody I have a problem with a linked list. I just get segmentation faults. Could anyone please help me? Thanks, this is the code __________________________ #include <stdio.h>...
30
by: Brian Elmegaard | last post by:
Hi, I am struggling to understand how to really appreciate object orientation. I guess these are FAQ's but I have not been able to find the answers. Maybe my problem is that my style and...
15
by: gjoneshtfc | last post by:
Hello, I have a simple problem that I just cannot get my head around! I currently have the following line in my ASP recordset: Recordset1.Source = "SELECT * FROM MainTable ORDER BY Price ASC"...
1
by: Bern McCarty | last post by:
I cannot figure out how to do this. It seems that the only way to introduce the "override" keyword into the mix is to give up on the simple property syntax. It seems that the designers of C++/CLI...
8
by: Bern McCarty | last post by:
I have a simple ref class in its own namespace that needs to coexist with a legacy typedef alias for "unsigned int" in the global namespace that has the identifier as itself. Everything compiles...
6
kenobewan
by: kenobewan | last post by:
Congratulations! You are one of the few who realise that over 80% of errors are simple and easy to fix. It is important to realise this as it can save a lot of time. Time that could be wasted making...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.