help with tutorial 45, 46, 47

+1 Lachlan S · April 10, 2015
Can anyone help me with these? does anyone know cans and can'ts of classes and stuff. i have been getting nothing but errors, undefined references, all sorts. I can be more specific but does anyone know general rules.

Some Questions:

people::people ( can the latter be different to the first?)

Pretty much, how can I properly write tutorial 45,46,47 with objects that were named differently to their classes? 

Post a Reply


- page 3
Oldest  Newest  Rating
+1 Michael Bradford · May 7, 2015
Error 1: It's exactly as the error says within the file people.cpp there is a line...

People::People(String x,Birthday bo)

Notice how String x has string capitalized it should be string x, as such its being interpreted as a variable name and NOT a type.
it should be as follows. I added a space after the comma because that's good programming style.

People::People(string x, Birthday bo)

Error 2: See error one above, since it thinks String is the identifier it doesn't know what to do with x. (Resolving error 1 automatically resolves this error).

Error 3-8: honestly this all looks like the compiler having problems with the pieces of information that follow that first error of String. Fix Error 1 and see if it resolves all the errors if any of them persist get back to me and paste the code YOU used so I can compare it with the source code on github in case something slipped in there.
+1 Michael Bradford · May 7, 2015
Also guys it's worth noting that besides the errors above the problems you have where it says "undeclared function (your constructor name)" sound like linker problems. 

If you haven't learned about a linker it basically links up your header, cpp and other files into simple .o (object files) and then into the single .exe file.

The reason you guys are running into this problem is you likely started up Code:blocks and just made the five files and copy-pasted the source from the GitHub. With only files in a folder the compiler doesn't know what to link together and is going to give you those "undeclared" things because even though we've formatted the class files correctly they aren't actually "linked" together.

The solution to this? Open Code:Blocks, make a new CB project, THEN add the source files in. It should then link properly and you should have the proper result.
+1 Michael Bradford · May 7, 2015
Sorry forgot to mention in that last post the reason the solution is making a Code:Blocks project is because the compiler will link things together automatically for you (that's why you probably haven't learned about linkers) but in order to do this it needs to be in a project. (This is how C:B handles it).
0 Lachlan S · May 13, 2015

That was it! Thank you so much Michael and Brian, you guys are awesome.

Thanks so much!!!!




Used in many types of software including music players, video games, and many large scale applications.

Bucky Roberts Administrator