473,473 Members | 2,131 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

implement association in C++

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....
Jul 22 '05 #1
2 4055
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.
Jul 22 '05 #2
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();
}

Jul 22 '05 #3

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

Similar topics

7
by: steve | last post by:
Hi, I just upgraded my php but ran into a problem. Never seen this before. Somehow it seems I lost php file association. When I do a http://localhost/something.php I get a prompt for dowload...
0
by: Stefano Noferi | last post by:
We are pleased to announce the foundation of the Zope Italia Association (AZI - Associazione Zope Italia). It was created by a couple of mailing list users in the last months (since march). ...
6
by: Justin F | last post by:
I have set up file association for my application (VB.Net). I'm having problems getting the filename that was double-clicked. On my machine at work, if the filename being passed in to the...
2
by: David | last post by:
Hi, I am trying to create a two way association between 2 objects. I intended to do it by having a pointer to each other but I am getting compilation errors. At the moment I can create both...
4
by: Sasha | last post by:
Hi everyone, What is the best way to implement many-to-many relationship between objects? Any examples or links are welcome! Thank you, Sasha
6
by: Nak | last post by:
Hi there, I am implementing file association from within my application, association that occurs after installation. Anyway, I remember a while back seeing a key in the registry that was used...
1
by: Doug Bell | last post by:
Hi, Suddenly clicking on an SLN File type will not open Visual Studio on my PC. Not sure what I have done. The association settings still look to be correct but I get an error message saying that...
5
by: =?Utf-8?B?RG91Z0U=?= | last post by:
I am at my wits end. VB .net is supposed to be an object oriented language. But I have tried hack after hack, and I can not get past either "Reference to a non-shared member requires an object...
1
by: CatchSandeepVaid | last post by:
I have posted this question in hibernate forums also.. As this forum is related to java, i am posting it here also ... In hibernate, presently one-to-one associations are fetched non-lazily... I...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
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: 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 ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.