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

Replies

- page 1
Oldest  Newest  Rating
0 Lachlan S · May 13, 2015
OH  MY GOD.

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

Thanks so much!!!!

:)
+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).
+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.
0 Lachlan S · May 6, 2015
I have tried it in Visual Studio 2013 and have 8 errors (copy and paste from github)

Error 1 error C2065: 'String' : undeclared identifier c:\users\lachlan\documents\visual studio 2013\projects\consolec++ lesson 1\consolec++ lesson 1\people.cpp 6 1 ConsoleC++ lesson 1

Error 2 error C2146: syntax error : missing ')' before identifier 'x' c:\users\lachlan\documents\visual studio 2013\projects\consolec++ lesson 1\consolec++ lesson 1\people.cpp 6 1 ConsoleC++ lesson 1

Error 3 error C2761: '{ctor}' : member function redeclaration not allowed c:\users\lachlan\documents\visual studio 2013\projects\consolec++ lesson 1\consolec++ lesson 1\people.cpp 6 1 ConsoleC++ lesson 1

Error 4 error C2059: syntax error : ')' c:\users\lachlan\documents\visual studio 2013\projects\consolec++ lesson 1\consolec++ lesson 1\people.cpp 6 1 ConsoleC++ lesson 1

Error 5 error C2065: 'x' : undeclared identifier c:\users\lachlan\documents\visual studio 2013\projects\consolec++ lesson 1\consolec++ lesson 1\people.cpp 7 1 ConsoleC++ lesson 1

Error 6 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\users\lachlan\documents\visual studio 2013\projects\consolec++ lesson 1\consolec++ lesson 1\people.cpp 7 1 ConsoleC++ lesson 1

Error 7 error C2065: 'bo' : undeclared identifier c:\users\lachlan\documents\visual studio 2013\projects\consolec++ lesson 1\consolec++ lesson 1\people.cpp 7 1 ConsoleC++ lesson 1

Error 8 error C2448: 'dataOfBirth' : function-style initializer appears to be a function definition c:\users\lachlan\documents\visual studio 2013\projects\consolec++ lesson 1\consolec++ lesson 1\people.cpp 8 1 ConsoleC++ lesson 1
+1 Brian Reed · April 29, 2015
Nope, not that simple, and will not work for every case.

I too found the answer (see my solution page one), it worked out great, but I retyped the code another day and back to square one. To me, Code Blocks seams to be organizing the order of the includes and once it establishes this order keeps it until hell freezes over.
Sometimes, I have been able to freeze hell over:D

Cheers,
Brian
0 Rami Abdelbaki · April 28, 2015
Hi everybody;

The solution is here:
you don't need to include the header file of birthday class in people.h
What you need to do is just removing that header file ( #include "Birthday.h" ) from the header file (People.h) and everything will go fine.
 

best wishes;
Rami
0 isabel baker · April 25, 2015
I am having many problems such as you speak of, I'm sure it's codeblocks.
Why do I think that because with out ever having to change my code, I have cured all of these simular problems by starting out new or restarting code blocks. It just gets confused and it is messing up on the stuff it does in the back ground. I will many times once starting out new and getting it to work, I will go back and try the old project that didn't work, only to find it working now.
I am going to start working with eclipse to see if it has problems with classes on different pages.
Codeblocks like visual studio does a lot of thing out of sight out of our minds which saves us a lot of time but when it messes up your screwed. Like unchecking and checking thing when we create a new class, where and what is being stored and how do we manualy do it or check it.
0 Lachlan S · April 23, 2015
Thanks for the heads up and material, I was just worried that I would never be able to do classes as it happened on tutorial 45 as well. i'll give the others a shot soon and try out ms visual studio (you can get it for free) (i need to learn it though)
0 Brian Reed · April 22, 2015
Lachian,

I reloaded Code Blocks again and run everything new again, but I'm now stuck like you are with:

People.cpp||error: expected constructor, destructor, or type conversion before '(' token 

I don't know exactly what is causing this issues, but I have exhausted all possible things I can think of to get it to work. I had it working once after playing around with it the first time, but since can't figure out what I did to make it work. Others have run the code without this issue or have used other platforms (because of Code Block issues).

 So, at this point I would suggest that you try and another compiler to run this lesson or the rest of the tutorials. However, I think you can finish the remaining tutorials without issue ( suggest reading on C++ compositions if you skip).

Anyone else have something to add?

Cheers,
Brian

C++

106,949 followers
About

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

Links
Moderators
Bucky Roberts Administrator