Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > implement association in C++

Reply
Thread Tools

implement association in C++

 
 
roadster
Guest
Posts: n/a
 
      06-16-2004
Hi,

I'm new to C++ and I don't know how I can implement an association
between two objects.

e.g. we have objects A and B. B has the following interface-function :
GetInfo()

From within a function of A I want to get info of object B : so I need
to call :
B->GetInfo();

This gives a compile error, saying that B is an unkown variable. I can
solve this by making B a global class, but I know that this isn't the
right way to do this.

How do I need to do this? Any examples?


Greetz....
 
Reply With Quote
 
 
 
 
valentin tihomirov
Guest
Posts: n/a
 
      06-16-2004
Map associates element from one set with elements of another set. It allows
for is 1-to-N association. If you want 1-to-1, you can join the sub-objects
into one class.


 
Reply With Quote
 
 
 
 
Rolf Magnus
Guest
Posts: n/a
 
      06-16-2004
roadster wrote:

> Hi,
>
> I'm new to C++ and I don't know how I can implement an association
> between two objects.
>
> e.g. we have objects A and B. B has the following interface-function :
> GetInfo()
>
> From within a function of A I want to get info of object B : so I need
> to call :
> B->GetInfo();
>
> This gives a compile error, saying that B is an unkown variable.


From your description above, B is a class, not an object. You need an
instance of your class to call the GetInfo function on.

> I can solve this by making B a global class,


You probably mean a global object.

> but I know that this isn't the right way to do this.
>
> How do I need to do this? Any examples?


Well, first you need to get an object of class B. If your A is supposed
to contain a B, it might look something like:

//... definition of class B

class A
{
public:
void doSomething();
private:
B b;
};

void A::doSomething()
{
b.GetInfo();
}

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to implement association relationship in Java newsnet customer Java 5 11-09-2006 01:24 PM
Closed :: [GAME] Word Association! The Don The Lounge 32 06-26-2005 05:23 PM
Xp association with none-beaconed SSID =?Utf-8?B?TmljLkY=?= Wireless Networking 1 12-13-2004 03:29 AM
"aquiring network address" (association but no connection) =?Utf-8?B?dGlt?= Wireless Networking 6 10-06-2004 09:51 PM
WinCE 4.2 802.11 Association problems =?Utf-8?B?QXBhY2hldGE=?= Wireless Networking 0 07-27-2004 09:44 PM



Advertisments