Class function does not link

I'm trying to create a class with some function about file, like this:

pes.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#ifndef PES_H;
#define PES_H
const unsigned BUF_SIZ=1024;

class File_element											
	{
	public:
	FILE *fin,*fout;
	void check();
	unsigned char buf[BUF_SIZ];
	size_t size;
	unsigned int fin_size, fout_size ;                          			
	unsigned int bp ;										
	File_element();
	};
#endif 


pes_supplement.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include "pes.h"
#include "stdafx.h"
#include <cstdlib>	
File_element::File_element()
{
	bp=0;
	fin_size=fout_size=0;
}

void File_element::check()
{
	if (fin==NULL) {printf("Input file cannot open"); exit(EXIT_FAILURE);
	if (fin==NULL) {printf("Output file cannot open"); exit(EXIT_FAILURE);
}


But the complier complaint:
1>f:\vz test\vz test\pes_supplement.cpp(7): error C2653: 'File_element' : is not a class or namespace name
1>f:\vz test\vz test\pes_supplement.cpp(8): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
I don't understand why do these errors occur.


Last edited on
IIRC stdafx.h must be first.
(that in the case that you need that VS especific header that stdafx.h is)

that
Last edited on
First thing I notice is you are using C, C++ mix.
For file handling in C++ use fstream header and ifstream and ofstream for input and out from/to files.

Instead of printf use cout, you need to include header iostream for it to work.
About the errors: I dont see any class related code at line 7 and function declaration/definition at line 8.
Is the source different from the one posted here?

Looking at the code I dont see apparent cause except what ne555 pointed out
Oh I forget. I delete lines for you guys easier to see. I compile it again

1>f:\vz test\vz test\pes_supplement.cpp(4): error C2653: 'File_element' : is not a class or namespace name
1>f:\vz test\vz test\pes_supplement.cpp(5): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

After put stdafx first, things work normal again. Thanks ne555 for helping.
Last edited on
Topic archived. No new replies allowed.