+ 2

What is wrong with this code?

So i tryed to reproduce the composition tutorial in codeblocks and i wrote the code just like it was in the tutorial just in separate files. And codeblocks gives out like 11 errors and i cant find out how to fix them on my own. /////Geburtstag.h///// #ifndef GEBURTSTAG_H #define GEBURTSTAG_H class Geburtstag { public: Geburtstag(); void DatumAusgabe(); protected: private: int Tag; int Monat; int Jahr; }; #endif // GEBURTSTAG_H /////Geburtstag.cpp///// #include "Geburtstag.h" Geburtstag::Geburtstag(int d,int m, int y){:Tag(d),Monat(m),Jahr(y)} Geburtstag::DatumAusgabe(){ cout<<Tag<<"/"<<Monat<<"/"<<Jahr<<"/"<<endl;} /////Person.h////// #ifndef PERSON_H #define PERSON_H class Person { private: string Name; public: Person(); void NameAusgabe(); protected: }; #endif // PERSON_H /////Person.cpp///// #include "Person.h" Person::Person(string n):Name(n) Person::NameAusgabe(){ cout<<Name<<endl; } { //ctor }

2nd Feb 2018, 1:31 PM
Lordi chan
Lordi chan - avatar
3 ответов
2nd Feb 2018, 2:34 PM
John Wells
John Wells - avatar
+ 3
Additionaly to what @rafal mentioned, I saw a few more mistakes: 1. If you use functions from the STL in a file and dont use "using namespace std;", you'll have to write std:: in front of all functions from the STL, e.g. std::cout and std::endl. 2. Similar to 1., if you use functions from a library, make sure to add that library to your file using #include, e.g. <iostream> in Geburtstag.cpp for std::cout. 3. Maybe a typing mistake, but in your ctor you put the initialization list into the curly braces, which is wrong - it comes before them. 4. When defining a function in a cpp.file, dont forget the return type of the function! 5. Also I dont know why you declared Geburtstag::NameAusgabe() {} inbetween your Person constructor, but currently it is a mistake. Thats everything for now from my point of view, cant find any more.
2nd Feb 2018, 2:00 PM
Shadow
Shadow - avatar
+ 2
in both of your .cpp files constructors have arguments, but in .h there is none, also use destructors
2nd Feb 2018, 1:40 PM
rafal