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 2
Oldest  Newest  Rating
+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.
__________________________________________________
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
0 Lachlan S · April 21, 2015
Any more help?
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
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 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 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
+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 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

C++

107,079 followers
About

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

Links
Moderators
Bucky Roberts Administrator