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
+1 Lachlan S · April 16, 2015
Nope, same things occurring, hopefully bucky could come to help, but hes probably too busy making videos and moderating to respond. Thanks for the input, but i tried the #include change and it still didn't work.
+1 Brian Reed · April 16, 2015
Lachian,

Sorry to here that did not work out. OK, lets start working the problem step by step.

So, to be clear, you are getting the same error messages as the ones you posted last time?

If so, that indicates to me that (since the error is in the main.cpp and refers to a class) the compiler can't find any reference to one of the other classes or both.

So, if your code is exactly the same and I ran it fine (after adding the missing #include), then the problem must be with the compilers connection to the other classes (because the error occurs while checking in main.cpp).

So, I have to ask, did you create a new project from scratch, then create new classes, or did you erase over the existing class files by pasting in the new code?

When the compiler hits an error its stops with a red square at the point of the error.
Post the code that is on that line (as this might not be the same line for me).
Then the error message for that line found in the "Biuld messages" Tab.

You'll get there, this is just a hickup;)

Cheers,
Brian

Notes:
________________________________________________
Things to check for when creating a new project:
Check compiler is "GNU GCC Compiler"
_________________________________________________
Things to check for when creating a new class:
Check that the "Has destructor" checkbox is Unchecked.
__________________________________________________
+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
+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).
+1 Lachlan S · April 15, 2015
Cool, thanks, ill try that later, its a bit late here. Anyway, I did think about that but it worked for bucky so I didn't think to change it.

Anyway, thanks.
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
0 Lachlan S · April 17, 2015
Now it has the constructor, deconstructor or type conversion error. This is really inconsistent, it did this before (last page) and the next morning after no changes it went to those three errors. I am so confused right now.

Specifically here (happened last time as well),


People:: People(String x,Birthday bo)

the space between : and P was on purpose so it would show properly on site, not like that in actual prog.
//here is full page


#include "People.h"
#include "Birthday.h"
#include
using namespace std;

People:: People(String x,Birthday bo)
: name(x), dataOfBirth(bo)
{
}

void People::printInfo(){
cout
0 Lachlan S · April 17, 2015
Thanks for all the help btw, i would've given up by now :D

C++

107,290 followers
About

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

Links
Moderators
Bucky Roberts Administrator