Headers

Hello i got 3 headers file and getting errors

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
  #include <iostream>
#include <string>
#include "Faktura.h"

using namespace std;

int main()
{
	Faktura* fakt = new Faktura(1, "Jakub Badura", "Klimkova 1607/4", 10);
	PolozkaFaktury* poloz = new PolozkaFaktury("wood ", 450.99);
	fakt->addPolozka(poloz);
	poloz = new PolozkaFaktury("steal", 500.45);
	fakt->addPolozka(poloz);
	poloz = new PolozkaFaktury("glass", 1500.99);
	fakt->addPolozka(poloz);
	poloz = new PolozkaFaktury("car", 1500.87);
	fakt->addPolozka(poloz);
	poloz = new PolozkaFaktury("steal", 4890.15);
	fakt->addPolozka(poloz);
	
	cout << "Pred" << endl;
	fakt->printPolozka();
	cout << "Celkova cena Faktury: " << fakt->sumPrice() << endl;
	cout << endl;

	fakt->removePolozka(3);

	cout << "Po" << endl;
	fakt->printPolozka();
	cout << "Celkova cena Faktury: " << fakt->sumPrice() << endl;

	system("PAUSE");
	return 0;
}



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#pragma once

#include <string>
#include <iostream>
#include "Person.h"
#include "PolozkaFaktury.h"

using namespace std;
using std::string;


class Faktura
{
private:
	int ID;
	int pocet;
	Person* osoba;
	PolozkaFaktury** pole;

public:
	Faktura(int ID, string jmeno, string adresa, int n);
	~Faktura();
	void addPolozka(PolozkaFaktury* polozka);
	bool removePolozka(int n);
	double sumPrice();
	void printPolozka();
	int getPocet();
	void increasePocet();
	void decreasePocet();
};


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#pragma once

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

using std::string;

class Person
{
private:
	string jmeno;
	string adresa;

public:
	Person(string jmeno, string adresa);
	string getName(string jmeno);
	string getAddress(string adresa);
};


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#pragma once

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

using std::string;

class PolozkaFaktury
{
private:
	string nazev;
	double cena;

public:
	PolozkaFaktury(string nazev, double cena);
	string getNazev();
	double getPrice();
};


When the heades is in one file its working, but when a put them seperatly a got this :
Severity Code Description Project File Line Suppression State
Error C2238 unexpected token(s) preceding ';' Project2Faktura c:\users\pc\source\repos\project2faktura\project2faktura\faktura.h 17
Error C2143 syntax error: missing ';' before '*' Project2Faktura c:\users\pc\source\repos\project2faktura\project2faktura\faktura.h 18
Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int Project2Faktura c:\users\pc\source\repos\project2faktura\project2faktura\faktura.h 18
Error C2238 unexpected token(s) preceding ';' Project2Faktura c:\users\pc\source\repos\project2faktura\project2faktura\faktura.h 18
Error C2061 syntax error: identifier 'PolozkaFaktury' Project2Faktura c:\users\pc\source\repos\project2faktura\project2faktura\faktura.h 23
Error C2143 syntax error: missing ';' before '*' Project2Faktura c:\users\pc\source\repos\project2faktura\project2faktura\faktura.h 17
Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int Project2Faktura c:\users\pc\source\repos\project2faktura\project2faktura\faktura.h 17

SRY for bad English.
Person.h does not need to include "Faktura.h"

PolozkaFaktura.h does not need to include "Faktura.h"


Faktura.h does not need to include Person.h and PolozkaFaktura.h
It is enough to forward declare those classes:
1
2
class PolozkaFaktury;
class Person;

Ty it wors now.
Error was because person and polozka was nod compiled;
Last edited on
Hello Jakubaz,

Do not edit a message and change it. It makes the thread hard to follow when something is missing.

No you do not have to include the other header files in any header file. use the forward declare that keskiverto showed you. Also you do not need the "#include"s that you have. Most "#includes" should only be in ".cpp" files.

Here is an idea of what your header files should look like:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#pragma once

#ifndef _PERSON_ 
#define _PERSON_

class Person
{
private:
	string jmeno;
	string adresa;

public:
	Person(string jmeno, string adresa);
	string getName(string jmeno);
	string getAddress(string adresa);
};

#endif // end !_PERSON_  


The "#ifndef" will keep the file from being included more than once.

And you should never put the statement using namespace std; in a header file. See:
http://www.lonecpluspluscoder.com/2012/09/22/i-dont-want-to-see-another-using-namespace-xxx-in-a-header-file-ever-again/

Also using using namespace std; WILL get you in trouble some day. Better to learn to type "std::" and learn what is in the standard name space now rather than later.

Hope that helps,

Andy
Topic archived. No new replies allowed.