class definitions

A

aliboyaci

class a {
int x(b * _b);
};

class b {
int y(a * _a);
};

i want to make a definiton like that but i have errors. how can i solve
this ?

error : 4
expected `;' before '(' token
 
V

Victor Bazarov

class a {
int x(b * _b);
};

class b {
int y(a * _a);
};

i want to make a definiton like that but i have errors. how can i
solve this ?

error : 4
expected `;' before '(' token

Look up "forward declaration" in the FAQ. And next time read the
FFAQ before posting, please.

V
 
O

osmium

class a {
int x(b * _b);

What do you *want* to have happen here? Is '*' meant to be the multiply
operator? b is (will be) a class, and classes have no value - only objects
have values. And what is "_b" supposed to represent?
 
V

Victor Bazarov

osmium said:
What do you *want* to have happen here? Is '*' meant to be the
multiply operator? b is (will be) a class, and classes have no value
- only objects have values. And what is "_b" supposed to represent?

Uh... It's a declaration of a funciton 'x' that takes a pointer to 'b'
and returns an 'int'...

V
 
O

osmium

osmium said:
What do you *want* to have happen here? Is '*' meant to be the multiply
operator? b is (will be) a class, and classes have no value - only
objects have values. And what is "_b" supposed to represent?

OK, I seen now what you wanted, and have already received an answer to your
question, I saw the leading underscore as a kind of "magic incantation" and
got sidetracked. Sorry about that.
 
A

ali

thanx alot Victor

next time i will first read to faq :)
as Victor said

forward declaration :

------a.h-------
class b;
class a {
int x(b * _b);
};
------a.h-------

------b.h-------
class a;
class b {
int x(a * _a);
};
------b.h-------
 
M

Mark P

ali said:
thanx alot Victor

next time i will first read to faq :)
as Victor said

forward declaration :

------a.h-------
class b;
class a {
int x(b * _b);
};
------a.h-------

------b.h-------
class a;
class b {
int x(a * _a);
};
------b.h-------

Just some suggestions...

I think your function declarations would be more readable if the * were
put immediately adjacent to the typename, e.g.:

int x(b* _b);

Additionally, I find that type names and variable names that differ only
be a punctuation symbol are confusing to look at.

And finally, user-defined names should not begin with an underscore as
these are reserved for the implementation.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top