473,406 Members | 2,371 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

how to create a member, which knows about the object it was created in

Hi,

I would like to let a member a of class A know about the object it
was created in:

A a(this);

'this' would be stored in a member of A, for example

B* b;

for this purpose I included A.h in B.h and B.h in A.h (without
problems) but when I try to declare the 'B* b;' I get a strange
error (error C2501 - the error message is in Japanese
(I use the Japanese version of Visual C++ .NET) and
says something like "even if the identifier was declared,
his shape is unspecified).

here is the miminum code producing the error:

int main(int argc, char* argv[])
{
return 0;
}

class A
{
public:
B* b; // if I comment this line out everything works fine
A(void) {};
~A(void) {};
};

class B
{
public:
// A* a;
B(void) {};
~B(void) {};
};

Actually I would like to also let B know about A, see the comment in
class B...

Is there anybody who can tell me, why this is not possible??
Or even better how it could be possible???
(or why it makes sense to forbid things like this - for the case
it doesn't make sense...)

any help??
Thanks a lot :), di

PS: The context of this problem is the following:
I try to implement a little Genetic Algorithm and have a
class 'Individual' with two members: 'Chromosome' and 'Phenotype'.
I want the Phenotype to be able to adress the corresponding
cromosome. As the individual knows about the
chromosome, the easyest way would be to let the phenotype know
about the individual it is belonging to....
Jul 19 '05 #1
1 1456

"di boruman" <di****@freenet.de> wrote in message
news:47**************************@posting.google.c om...
Hi,

I would like to let a member a of class A know about the object it
was created in:

A a(this);

'this' would be stored in a member of A, for example

B* b;

for this purpose I included A.h in B.h and B.h in A.h (without
problems) but when I try to declare the 'B* b;' I get a strange
error (error C2501 - the error message is in Japanese
(I use the Japanese version of Visual C++ .NET) and
says something like "even if the identifier was declared,
his shape is unspecified).

here is the miminum code producing the error:

int main(int argc, char* argv[])
{
return 0;
}

Add this here, its called a forward declaration.

class B;
class A
{
public:
B* b; // if I comment this line out everything works fine
A(void) {};
~A(void) {};
};

class B
{
public:
// A* a;
B(void) {};
~B(void) {};
};

Actually I would like to also let B know about A, see the comment in
class B...

Is there anybody who can tell me, why this is not possible??
Or even better how it could be possible???
(or why it makes sense to forbid things like this - for the case
it doesn't make sense...)

any help??
Thanks a lot :), di


john
Jul 19 '05 #2

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

Similar topics

10
by: Gianni Mariani | last post by:
While digging for a work around for a VC++7.1 compiler bug I came to find an interesting thing about pointer to member conversions. struct A { int a; }; struct B : A
9
by: jon wayne | last post by:
OK! I had this nagging doubt Consider (without worrying abt access specifiers) class Kid : public Parent{...}; Parent::someFunc() { Kid k; }
7
by: dog | last post by:
I've seen plenty of articles on this topic but none of them have been able to solve my problem. I am working with an Access 97 database on an NT4.0 machine, which has many Access reports. I...
4
by: Ray | last post by:
I want to dynamically load DLLs (created from VB) and instantiate a class with a particular name, like "ProcessClass". I am able to load the DLL and confirm there is a class by that name BUT I...
15
by: Amit D.Shinde | last post by:
I am adding a new picturebox control at runtime on the form How can i create click event handler for this control Amit Shinde
37
by: Joergen Bech | last post by:
(Slightly religious question): Suppose I have the following class: ---snip--- Public Class MyClass Private _MyVariable As Integer Public Property MyVariable() As Integer Get
6
by: Peter Nurse | last post by:
For reasons that are not relevant (though I explain them below *), I want, for all my users whatever privelige level, an SP which creates and inserts into a temporary table and then another SP...
13
by: JohnQ | last post by:
The implementation of classes with virtual functions is conceptually easy to understand: they use vtables. Which begs the question about POD structs: how are they associated with their member...
3
by: Rahul | last post by:
While reading Inside the C++ object model I came through the following paragraph Point3d origin, *ptr = &origin; A) origin.x = 0.0; B) ptr->x = 0.0; The book says "A & B statements performs...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
0
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...

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.