• Popular Now

• 9
• 10
• 9
• 10
• 10

This topic is 4616 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Share on other sites
Get it to work with two .cpp files. You're going to need to get used to this at some point: better sooner than later...

I assume your code looked sort of like the following (really cut down) code:
// paddle.h#ifndef _UKDEVELOPER__PADDLE_H_#define _UKDEVELOPER__PADDLE_H_class Paddle{    public:        void someFunction();}#endif
// paddle.cpp#include "paddle.h"voidPaddle::someFunction(){     // implementation}
// events.cpp#include "paddle.h"Paddle myPaddle;voidkeyHandler(){     myPaddle.someFunction();}

What compiler are you using? Which IDE (if any)?

Share on other sites
If the compiler gives problems about 'multiple declaration' it also tells you where the problems occur. Note that your .h should only include the things that you need in events.cpp, and not those that you need in paddle.cpp. So if you've got a global variable int x in paddle.cpp that you don't need to use directly in events.cpp, then don't put it in the header file paddle.h, but simply declare it in paddle.cpp.

Share on other sites
I'm using VS2005 Express Beta 2.

lucky_monkey, that's exactly how my code was before I hacked round it.

So are you saying using a class here is a bad idea? Could I create some other small function as an extern to act as a "bridge" between the two source files, meaning I only need to use the include once? That might work, I'm thinking.

Share on other sites
Exactly what errors were you getting? Were they compiler errors or linker errors? If your code looked like lucky_monkey's snippet (with the addition of a semi-colon at the end of the class definition) then you should not have been getting multiple declaration/definition errors.

Enigma

Share on other sites
Quote:
 Original post by EnigmaIf your code looked like lucky_monkey's snippet (with the addition of a semi-colon at the end of the class definition) then you should not have been getting multiple declaration/definition errors.Enigma

I fixed it.

class BRPaddle{public: // codeprivate: // code}Paddle; // Removing this and putting BRPaddle Paddle into my .cpp file solved the problem!