tags:

views:

123

answers:

2

Hi,

I am new to C++, and I'm having trouble segmenting my code. Here is my setup:

  • A main.cpp that calls function that takes 2 int and 1 char* and returns int
  • A function.h that contains, among other things, a function prototpye

    int function(int a, int b, char* c);

  • A function.cpp that contains the actual function definition.

I have used #include "function.h" in both function.cpp and main.cpp.

When I try to compile my code, I get that there is an undefined reference to function(int, int, char*) in my main() function.

What's wrong?

*smacks head.

I left off a .cpp after the function file, so eclipse wasn't compiling that file. sorry!

A: 

*smacks head.

I left off a .cpp after the function file, so eclipse wasn't compiling that file. sorry!

I recommend you just delete your question (to avoid confusing others' and wasting their time).
Alex Martelli
How I wish I had read this comment 2 minutes back!.
Chubsdad
I voted to close the question. Please delete it so we don't waste time, or at the VERY least edit it so this little notice isn't stuck at the bottom of the page, separate from it. — ah, actually I have the ability to do the latter for you!
Potatoswatter
+1  A: 
Max Kielland
Names beginning with an underscore followed by a capital letter or another underscore are reserved to the implementation. Best not to begin include guards with an underscore.
James McNellis
@James: Since when *aren't* include guards double-underscore-filename-double-underscore? I think it's a pretty common practice. I like to add the project name, single underscore, then the file though (readability and less chance of conflicts).
peachykeen
@peachykeen: Just because some projects use that format does not make it acceptable. I've never used reserved names for header guards in my C++ projects and I know (at least most of) Boost does not. If it's easy to do it right, why do it wrong?
James McNellis
Well, as Peachykeen says, it is common practice, even a lot of IDE create them for you. I think the chanse of a double-underscore-filename-H-double-underscore would be in conflict with any reserved name is minimal, unless you really trie hard to name your file to create a conflict. Doing it right from the begining? Well, in large projects and especially when you share the same modules in several projects, this mecanism will save you a lot of debug time. But if you are capable of not doing it in this way and still make it work perfect in large projects and shared modules: Congratz!!
Max Kielland
Just as the name with the double-underscore is unlikely to be reserved, so is the same name *without* it unlikely to conflict with anything. Or, it's completely acceptable to put underscores at the end.
Potatoswatter
Actually, it's names beginning with an underscore followed by a capital letter, names with a double-underscores __anywhere__ in them, and all names beginning with an underscore in the global namespace. And I agree that this rule should be followed. Doing so doesn't cost much and it greatly reduces the possibility of name clashes when code gets ported ten years from now.
sbi
@Potato, @sbi: Ohhhhh, you're right: double underscores _anywhere_ in a name are prohibited. *sigh*
James McNellis