Implementation Files & C++

W

Will Oram

Normally I use PB for Cocoa, but now I'm using it for a school project.
I have an implementation file, a header, and a main cpp file.

I have a class defined in the header, which I will simplify to the
basics for viewing audiences:

class SomeClass {
public:
SomeClass(); //constructor
};

...with function members defined in the implementation:

SomeClass::SomeClass() {
cout << "hello\n";
}

Trouble is, PB complains that I've already defined SomeClass elsewhere.
It doesn't *show* me where, though.

I've tried this in CodeWarrior too, with similar complaints. Now I'm
thinking it's my fault and not a compiler quirk. But I essentially
copied the above out of my textbook!

Any thoughts? Thanks.
 
A

Attila Feher

Will Oram wrote:
[SNIP]
Trouble is, PB complains that I've already defined SomeClass
elsewhere. It doesn't *show* me where, though.

I've tried this in CodeWarrior too, with similar complaints. Now I'm
thinking it's my fault and not a compiler quirk. But I essentially
copied the above out of my textbook!

Any thoughts? Thanks.

I have no idea what PB is, but what I am sure about is that you need to post
a minimal, compilable code what shows your problem. With this information
we could only guess.

http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.8
 
H

Howard

Normally I use PB for Cocoa, but now I'm using it for a school project.
I have an implementation file, a header, and a main cpp file.

I have a class defined in the header, which I will simplify to the
basics for viewing audiences:

class SomeClass {
public:
SomeClass(); //constructor
};

..with function members defined in the implementation:

SomeClass::SomeClass() {
cout << "hello\n";
}

Trouble is, PB complains that I've already defined SomeClass elsewhere.
It doesn't *show* me where, though.

I've tried this in CodeWarrior too, with similar complaints. Now I'm
thinking it's my fault and not a compiler quirk. But I essentially
copied the above out of my textbook!

Any thoughts? Thanks.

What do your #include's look like? Perhaps you're including the header
twice in the same compilation unit. If so, you can fix that by putting the
following lines (or something similar) around the contents of your header
file:

#ifndef h_myclass
#define h_myclass

// rest of header file contents here...

#endif


-Howard
 

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

No members online now.

Forum statistics

Threads
474,143
Messages
2,570,822
Members
47,368
Latest member
michaelsmithh

Latest Threads

Top