By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,106 Members | 1,079 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,106 IT Pros & Developers. It's quick & easy.

Problem With Visual C++

P: n/a
Suppose I have 2 classes X & Y declared in X.h & Y.h and defined in
X.cpp & Y.cpp. If I have a function which returns an object of X in Y
and one which returns an object of X in Y how where and in what order
do I include the files X,Y.cpp,.h

Also sometimes while working in Visual C++, after adding some code
manually I find that some classes dissapear from the class view tab. If
I try to add the class again with the already existing files it shows
that the class already exists. Whats happening??

Jul 23 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
By the way - the other problem is MS VC specific, but try deleting the class
wizard file (.clw extension) and re-opeining the workspace).

Aiden

"adbarnet" <ad******@barnet.com> wrote in message
news:42**********@127.0.0.1...

I assume you meant X includes Y and Y includes X? In that case you have a
circular dependency, which can be pretty heinous. The best solution is to
re-work the code to remove one dependency (consider combining X and Y via
a third class Z to achieve the intended goal i.e. Z includes X and Y).
Alternatively - can any of the declarations of X or Y be made into
references or pointers? That way you can forward declare them rather that
including the entire declaration.

<mp******@gmail.com> wrote in message
news:11**********************@l41g2000cwc.googlegr oups.com...
Suppose I have 2 classes X & Y declared in X.h & Y.h and defined in
X.cpp & Y.cpp. If I have a function which returns an object of X in Y
and one which returns an object of X in Y how where and in what order
do I include the files X,Y.cpp,.h

Also sometimes while working in Visual C++, after adding some code
manually I find that some classes dissapear from the class view tab. If
I try to add the class again with the already existing files it shows
that the class already exists. Whats happening??


Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com


Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Jul 23 '05 #2

P: n/a
mp******@gmail.com wrote:
Suppose I have 2 classes X & Y declared in X.h & Y.h and defined in
X.cpp & Y.cpp. If I have a function which returns an object of X in Y
and one which returns an object of X in Y how where and in what order
do I include the files X,Y.cpp,.h

class Y;

class X
{
public:
void somefunc(Y obj);
};
class Y
{
public:
void somefunc(X obj);
};
void X::somefunc(Y obj) {}
void Y::somefunc(X obj) {}
int main()
{
X x;

Y y;

x.somefunc(y);

y.somefunc(x);
}


--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 23 '05 #3

P: n/a
well Ioannis,

I've tried that but it shows the error

error C2501: 'Y' : missing storage-class or type specifiers

by the way I use Visual C++

Jul 23 '05 #4

P: n/a
mp******@gmail.com wrote:

well Ioannis,

I've tried that but it shows the error

error C2501: 'Y' : missing storage-class or type specifiers

by the way I use Visual C++


replace the pass-per-value with a pass-per-reference

class X
{
public:
void somefunc(const Y& obj);
};
--
Karl Heinz Buchegger
kb******@gascad.at
Jul 23 '05 #5

P: n/a
mp******@gmail.com wrote:
well Ioannis,

I've tried that but it shows the error

error C2501: 'Y' : missing storage-class or type specifiers

by the way I use Visual C++

It compiles with the last version of VC++ here with only a stupid
warning which looks it is fixed in current VC++ 2005 beta:
c:\c\temp.cpp(27) : warning C4700: local variable 'y' used without
having been i
nitialized
But it compiles. What version of VC++ are you using?

--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 23 '05 #6

P: n/a
I use Visual C++ 6.0 . I dont have access to VC++2004 or 5 so is there
any way to get around this problem

Jul 23 '05 #7

P: n/a
mp******@gmail.com wrote:
I use Visual C++ 6.0 . I dont have access to VC++2004 or 5 so is there
any way to get around this problem

Unfortunately, VC++ 6 is very old and is not much ISO C++ compliant.


--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 23 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.