🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

C++ Workshop - OO Analysis, Design, & Porgramming (Ch. 6 & Ch. 11)

Started by
75 comments, last by Dbproguy 16 years, 2 months ago
Quote: when i do this (i.e. include the declaration file header into both main and the implementation file), i get a linker error:

[Linker error] undefined reference to `Soldier::Soldier()'


I already addressed this one. Assuming this is the only error you get; it means you didn't define your constructor, you just declared it.
Advertisement
Quote: Original post by Deyja
I already addressed this one. Assuming this is the only error you get; it means you didn't define your constructor, you just declared it.

I think it more likely that he did define it, but he is compiling and linking only main.cpp, where the definition is in another file.
Ah, but then he wouldn't have gotten those other errors in the first place, see?
Quote: Original post by Deyja
Ah, but then he wouldn't have gotten those other errors in the first place, see?

Hmm, yeah. You may be right.
I have 3 files all in same project;

ClassSoldier.hpp = contains my class' declaration.
Soldier.cpp = contains my class' definition (implementation), which #includes ClassSoldier.hpp. (and yes, it has the constructors definition)
main.cpp = main, which #includes ClassSoldier.hpp


and i get link error
[Linker error] undefined reference to `Soldier::Soldier()'


according to jflanglois:
Quote: It's the job of the linker to then combine the compiled object code from both main.cpp and Soldier.cpp into a single executable. This is usually hidden from you when you use an IDE, which implicitly links together every implementation file that is in your project.
Quote: (and yes, it has the constructors definition)
The definition; or just the declaration? Post the code; all of it.
Where did the C++ Workshop - Week 5 (Ch. 6 & 11) - Quizzes and Exercises thread go ? I remember seeing it earlier this week...
I noticed the same thing. Go to the top and where it says show topics for last 10 days and change that to last 30 days and you will see the Quizzes and Exercise thread.
jflanglois, deyja;

ok i tracked the problem; i declared a default constructor (and 2 more overloaded constructors) but implemented only my other overloaded constructors, not the dafeult one i declared. n00bish of me.

thanx for ur help
Pardon me but...where are the answers of the C++ Workshop - Week 5 (Ch. 6 & Ch. 11) - Quizzes and Exercises ?

This topic is closed to new replies.

Advertisement