//myClass.h
class myClass
{
};
//myOtherClass.h
class myClass;
class myOtherClass
{
};
//myOtherClass.cpp
#include "myClass.h"
//some other stuff...
Is the second one ever going to bring up problems? I know that the first method will occasionally cause an error, because of the order that files are compiled in, I believe, which is why sometimes the second method is often used.
I was thinking of just using the second method as a 'practice', but before I do, I want to find out if it's going to screw anything up later.
So, thanks in advance for any responses =p.
Last edited by XianForce on Mon Dec 28, 2009 5:17 pm, edited 2 times in total.
Really, what you should be aiming for is not which of those to use, but how to design your program's structure so that you never have use either of those. Circular dependancies are a bitch and if you can at all avoid them I would highly recommend doing so.
I also understanding avoiding them isn't always possible without refactoring major portions of your project (something nobody wants to do), so as for which method I use, the latter. They're both the same thing though from what I can see.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches!
dandymcgee wrote:Really, what you should be aiming for is not which of those to use, but how to design your program's structure so that you never have use either of those. Circular dependancies are a bitch and if you can at all avoid them I would highly recommend doing so.
I also understanding avoiding them isn't always possible without refactoring major portions of your project (something nobody wants to do), so as for which method I use, the latter. They're both the same thing though from what I can see.
Unless you put everything into a single file, I don't see how you could get around using one of those (unless there's some other method I haven't seen).
The former just seems a bit cleaner to me, but then when I start coming to places where I have to use the latter, I start questioning whether I should even use the former at all...
dandymcgee wrote:Really, what you should be aiming for is not which of those to use, but how to design your program's structure so that you never have use either of those. Circular dependancies are a bitch and if you can at all avoid them I would highly recommend doing so.
I also understanding avoiding them isn't always possible without refactoring major portions of your project (something nobody wants to do), so as for which method I use, the latter. They're both the same thing though from what I can see.
Unless you put everything into a single file, I don't see how you could get around using one of those (unless there's some other method I haven't seen).
The former just seems a bit cleaner to me, but then when I start coming to places where I have to use the latter, I start questioning whether I should even use the former at all...
Sorry I didn't read the comments right. Usually you use separate code boxes for each file.
The first method is the correct method and you should always use that when you can. The second method is the circular dependency fix, which you should try to avoid to begin with.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches!
dandymcgee wrote:Really, what you should be aiming for is not which of those to use, but how to design your program's structure so that you never have use either of those. Circular dependancies are a bitch and if you can at all avoid them I would highly recommend doing so.
I also understanding avoiding them isn't always possible without refactoring major portions of your project (something nobody wants to do), so as for which method I use, the latter. They're both the same thing though from what I can see.
Unless you put everything into a single file, I don't see how you could get around using one of those (unless there's some other method I haven't seen).
The former just seems a bit cleaner to me, but then when I start coming to places where I have to use the latter, I start questioning whether I should even use the former at all...
Sorry I didn't read the comments right. Usually you use separate code boxes for each file.
The first method is the correct method and you should always use that when you can. The second method is the circular dependency fix, which you should try to avoid to begin with.
dandymcgee wrote:Really, what you should be aiming for is not which of those to use, but how to design your program's structure so that you never have use either of those. Circular dependancies are a bitch and if you can at all avoid them I would highly recommend doing so.
I also understanding avoiding them isn't always possible without refactoring major portions of your project (something nobody wants to do), so as for which method I use, the latter. They're both the same thing though from what I can see.
Unless you put everything into a single file, I don't see how you could get around using one of those (unless there's some other method I haven't seen).
The former just seems a bit cleaner to me, but then when I start coming to places where I have to use the latter, I start questioning whether I should even use the former at all...
Sorry I didn't read the comments right. Usually you use separate code boxes for each file.
The first method is the correct method and you should always use that when you can. The second method is the circular dependency fix, which you should try to avoid to begin with.
I've actually heard differently. If you can get away with just prototyping and not including another header file, you should go with that. Otherwise you're creating a dependency on header B for header A. Now if you change anything in header B, header A has also changed, and everything including header A must be recompiled.
[quote=GyroVorbis]I've actually heard differently. If you can get away with just prototyping and not including another header file, you should go with that. Otherwise you're creating a dependency on header B for header A. Now if you change anything in header B, header A has also changed, and everything including header A must be recompiled.[/quote]
Ahh, that's good to keep in mind; But I'm using functions from these classes, so I gotta include the header =/.