Another beginner question...

Pages: 12
closed account (48T7M4Gy)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
// birthday.cpp

#include "birthday.h"

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

void birthday::printdate() {
	cout << month << "/" << day << "/" << year << endl;
}
closed account (48T7M4Gy)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// main
#include <iostream>
#include <string>

#include "people.h"
#include "birthday.h"

using std::cout;
using std::endl;
using std::string;

int main()
{
	birthday bob(6, 7, 1990);
	people me("Bob", bob);
	me.printinfo();

	cout << "Finished";
}
Last edited on
closed account (48T7M4Gy)
That's the lot of the files :)
Ok wow that worked! thanks so much!
now could you explain what was changed?

If i use those standards or headers should they work for now on? I also didnt know you could have int without variable character.

why does the header file need to specify those stds?
closed account (48T7M4Gy)
C:\people.h|9|error: 'Birthday' has not been declared|
C:\main.cpp||In function 'int main()':|
C:\main.cpp|9|error: 'bo' was not declared in this scope|
C:\main.cpp|10|error: 'class people' has no member named 'printdate'|


I'm a bit in the dark here too but it should be birthday, not Birthday in your main.

Also make sure you have bo as the birthday object not bob, better still make it xyz

1
2
3
4
5
6
7
8
int main()
{
	birthday xyz(6, 7, 1990);
	people me("Bob", xyz);
	me.printinfo();

	cout << "Finished";
}
Last edited on
I changed my header files to the #pragma once and added the using std parts. But I did not change my main file and it ran fine. here is my main file that is working:
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include "birthday.h"
#include "people.h"
using namespace std;

int main()
{
	birthday bo(6, 7, 1990);
	people me("Bob", bo);
	me.printinfo();

	cout << "Finished";
}


closed account (48T7M4Gy)
Yep, I can believe that would do the trick. Looks like you're in business perp. I hope you understand what's happened and why, ie there's no magic.

Cheers :)
I think i understand. What is #pragma once?
And with the header files, the .h didnt know to use the "standard" functions like cpp files. you would think the header files would not need that info
closed account (48T7M4Gy)
The cpp files don't 'know' about the header file unless you tell them.

It's the same with any of the #includes - essentially they are instructions to the linker exactly the same way cout means zip unless you #include <iostream> where all the meaning is.

Let's face it though, at least the linker/compiler error reporting tells you what it can't work out.

#pragma once is a directive to only read/link that class once.
Topic archived. No new replies allowed.
Pages: 12