C++ code/compile help

ToeMissile

Pronouns: zie/zhem/zer
<Gold Donor>
2,718
1,659
So having an issue that my tired noob eyes/brain can't work out. Read my notes/book/looked online to no avail. I know it's something simple that I'm just not seeing.. anyhow, i'll only post one set of .h/.cpp as the others are basically the same. The main.cpp is provided by the instructor.

When I compile, I'm getting undefined reference errors for any call to/for a function from the class
Code:
In function `TestStudent()':
main.cpp[ATTACH=full]85254[/ATTACH].text+0x24c): undefined reference to `CStudent::CStudent()'
main.cpp[ATTACH=full]85255[/ATTACH].text+0x257): undefined reference to `CStudent::GetGPA()'
main.cpp[ATTACH=full]85256[/ATTACH].text+0x2ae): undefined reference to `CStudent::CStudent(CStudent const&)'
main.cpp[ATTACH=full]85257[/ATTACH].text+0x2b9): undefined reference to `CStudent::GetGPA()'
main.cpp[ATTACH=full]85258[/ATTACH].text+0x328): undefined reference to `CStudent::CStudent(double)'
[code][/spoiler]

[u]teacher.h[/u]
[QUOTE][/QUOTE][u]teacher.cpp[/u]
[QUOTE][/QUOTE]
[u]main.cpp[/u]
[QUOTE][/QUOTE]
 

Attachments

  • frown.png
    frown.png
    804 bytes · Views: 2
  • frown.png
    frown.png
    804 bytes · Views: 2
  • frown.png
    frown.png
    804 bytes · Views: 2
  • frown.png
    frown.png
    804 bytes · Views: 2
  • frown.png
    frown.png
    804 bytes · Views: 2
30
0
Does student.h have all the functions from your error? Do you have a student.cpp? Are the functions in question defined in student.cpp? Are you sure it's getting compiled in?
 

Chancellor Alkorin

Part-Time Sith
<Granularity Engineer>
6,029
5,915
Yeah, we'd need to see the declaration for the student part, not the teacher part, unless that is also giving you an error. Looks like you're not defining CStudent properly, or (and I'm guessing here, because you didn't include the code) your #ifndef at the top of student.h is actually an #ifdef and it's never getting included at all.
 

Kharza-kzad_sl

shitlord
1,080
0
Not sure why it can't find the gets and sets, but the constructors aren't written. I think you can just let the compiler make the default CStudent(); one. You'll need to write the ones that take a reference and a double.
 

Psypher_sl

shitlord
83
0
You need to implement the constructors that you defined in you header files. Until you do that, the compiler won't even be able to create the obj to link, so you'll get errors for every symbol that it can't resolve.

So, in classroom.cpp, you'll need to implement the two constructors, in student.cpp there should be 3 constructors, and for teacher.cpp there are 3 constructors. Now, you COULD implement them in the header files as well, but probably just best that you get into the habit of keeping all the implementations in your cpp file. As an example, in your student.h you could have CStudent() { }; vs CStudent::CStudent() { } in the cpp.