Composition lesson

0 John Shaw · October 9, 2014
Hi all
,
I'm a newbie to c++

I have reached lesson 47 of Bucky Roberts lessons.

try as I might I can not get this tutorial working,

I have gone over the tutorial (paused the youtube video on each file (.h, .cpp)
Still can not see any difference between my code and Bucky's!!

Can any one give me some pointers as this has been going on now for 16 hours (yes i'm that sad !! lol)
I had to go over it piece by piece.

any help really appreciated..
John S. 

Post a Reply

Replies

Oldest  Newest  Rating
0 John Shaw · October 13, 2014
Hi,

Really sorry to bother you again, but I have managed to get the Composition program working,

If I include the following in main.cpp:

 #include "Birthday.cpp"

 #include "People.cpp"

The tutorial works like a dream :)
0 John Shaw · October 12, 2014
49 Compositon.cpp


#include<iostream> // Pre-processor directive
#include "Birthday.h"
#include "People.h"
using namespace std;


int main() {
Birthday birthobj(12,28,1986);

People buckyroberts("Bucky Roberts",birthobj);

buckyroberts.printinfo();

}
//------------------------------------------------------------//


Birthday.h


#ifndef BIRTHDAY_H
#define BIRTHDAY_H




#include <string> // Temp
#include "People.h" // Temp
using namespace std; // Temp
class Birthday


{
public:
Birthday (int m,int d,int y);
void printdate();

private:
int month;
int day;
int year;


};
# endif // BIRTHDAY_H




//---------------------------------------------------------//


Birthday.cpp


#include<iostream>
#include "Birthday.h"
// #include "People.h" // Temp
using namespace std;




Birthday::Birthday(int m, int d, int y)
{
month=m;
day=d;
year=y;
}


void Birthday::printdate(){
cout<<month<<"/"<<day<<"/"<<year<<endl;
}




//------------------------------------------------------------//


People.h


#ifndef PEOPLE_H
#define PEOPLE_H


#include <string>
#include "Birthday.h"


using namespace std;


class People


{
public :
People(string x, Birthday bo);
void printinfo();
private:
string name;
Birthday dateofbirth;



};


#endif // PEOPLE_H


//---------------------------------------------------------//


People.cpp


#include<iostream>
#include "Birthday.h"
#include "People.h"
using namespace std;


People:eople()
: name(x), dateofbirth(bo)
{
}


void People::printinfo(string x, Birthday bo)
{ cout<<name<<" was born on ";
dateofbirth.printdate();
}


FAULT LOG


C:\Users\John\AppData\Local\Temp\cc4lVaby.o 49 Composition.cpp.text+0x2c): undefined reference to `Birthday::Birthday(int, int, int)'


C:\Users\John\AppData\Local\Temp\cc4lVaby.o 49 Composition.cpp.text+0x77): undefined reference to `People:eople(std::string, Birthday)'


C:\Users\John\AppData\Local\Temp\cc4lVaby.o 49 Composition.cpp.text+0x9b): undefined reference to `People::printinfo()'


c:\program files (x86)\dev-cpp\mingw64\x86_64-w64-mingw32\bin\ld.exe C:\Users\John\AppData\Local\Temp\cc4lVaby.o: bad reloc address 0x14 in section `.text$_ZN6PeopleD1Ev[_ZN6PeopleD1Ev]'


C:\Users\John\Documents\C++ Folder\Tutorial Course Programs\collect2.exe [Error] ld returned 1 exit status
Yes I was using code blocks.

I'm now using Dev-c.
0 John Shaw · October 9, 2014
Ok here is the :

main cpp

#include <iostream>  // Pre-processor directive
#include "Birthday.h"
#include "People.h"
using namespace std;
int main(){
 Birthday birthObj(12,28,1986);
 People buckyRoberts("Bucky Roberts", birthObj);
 buckyRoberts.printInfo(); // printInfo
}

Birthda.cpp

#include "People.h" // Temp
#include "Birthday.h"
#include <iostream>
using namespace std;

Birthday::Birthday(int m,int d,int y)
{
month = m;
day = d;
year = y;
}
void Birthday::printDate(){
cout<<month<<"/"<<day<<"/"<<year<<endl;
}

People.h

#ifndef PEOPLE_H
#define PEOPLE_H
#include <string>
#include "Birthday.h"
using namespace std;
class People
{
    public:
            People(string x, Birthday bo);
            void printInfo();
    private:
            string name;
            Birthday dateOFBirth;
};
#endif // PEOPLE_H

Birthday.h

#ifndef BIRTHDAY_H
#define BIRTHDAY_H
// using namespace std;  // Not in Bucky Tutorial ?
// #include <string> // Temp
// #include "People.h" // Temp
// using namespace std; // Temp
class Birthday
{
public:
    Birthday(int m, int d, int y);
    void printDate();
private:
    int month;
    int day;
    int year;
};
#endif // BIRTHDAY_H

People.cpp

#include "People.h"
#include "Birthday.h"
#include <iostream>
using namespace std;

People:People(string x, Birthday bo)
:name (x), dateOFBirth(bo)
{
}
void People::printInfo(){
cout<<name<<" was born on ";
dateOFBirth.printDate();
}

Error Msg's

C:\Users\John\Documents\C++ Folder\Tutorial Course Programs\49 Composition.o:49 Composition.cpp|| undefined reference to `Birthday::Birthday(int, int, int)'|

C:\Users\John\Documents\C++ Folder\Tutorial Course Programs\49 Composition.o:49 Composition.cpp|| undefined reference to `People:eople(std::string, Birthday)'|

C:\Users\John\Documents\C++ Folder\Tutorial Course Programs\49 Composition.o:49 Composition.cpp|| undefined reference to `People::printInfo()'|


||=== Build failed: 3 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
  • 1

C++

107,010 followers
About

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

Links
Moderators
Bucky Roberts Administrator