error-type

Hi all.. I have the following header, the class "site" works in other classes, especially in main, but I was not able to compile because of the following errors. All other classes are working fine, but I cannot define an object of type 'syst*', where I can define the object 'syst*' in other classes, or especially main. I need help to solve this.. Thank you..

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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
site.h:
#ifndef SITE_H
#define SITE_H

#include "file_reader.h"
#include "timer.h"
#include "coordinates.h"
#include "systm.h"

class site
{
private:
	int lmult;
	int rmult;
	double m;
	systm* sys;
	coordinates* coor;
	site* left;
	site* right;
	site* up;
	site* down;
	site* in;
	site* out;
	
public:
	site(coordinates* c, systm* s)
	{
		coor = c;
		sys = s;
		lmult = 1;
		rmult = 1;
		if (coor->getZ() == 0)
			lmult = -1;
		else if (coor->getZ() == sys->getSize()-1)
			rmult = -1;
		left = sys->getSite(coor);
	}
	void randomize()
	{
		m = rand();
	}
	site* getSite() {return this;}
	void update()
	{
	}
};

#endif 


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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
systm.h:
#ifndef SYSTM_H
#define SYSTM_H

#include <math.h>

#include "timer.h"
#include "site.h"
#include "coordinates.h"

class systm
{
private:
	site**** mag;
	int** spin;
	int size;
	int dim;
	int approx;
	double temp, aniso;
	void initSpin(int d)
	{
		// Initialize all possible spin arrays
		spin = new int*[2*d];
		for (int i = 0; i<2*d; i++)
			spin[i] = new int[(int)(pow(2.0, 2*d)+0.5)];
	}
public:
	systm(int d, int n, int app)
	{
		size = n;
		dim = d;
		mag = new site***[size];
		for (int i = 0; i<size; i++)
		{
			mag[i] = new site**[size];
			for (int j = 0; j<size; j++)
			{
				mag[i][j] = new site*[size];
				for (int k = 0; k<size; k++)
					mag[i][j][k] = new site(new coordinates(i,j,k), this);
			}
		}

		initSpin(d);
	}

	void randomize()
	{
		timer* tim = new timer();
		srand(tim->getRawTime());
		for (int i = 0; i<size; i++)
			for (int j = 0; j<size; j++)
				for (int k = 0; k<size; k++)
					mag[i][j][k]->randomize();
	}
	site* getSite(coordinates* coor) {return mag[coor->getX()][coor->getY()][coor->getZ()];}
	int getSize() {return size;}
};
#endif 


1
2
3
4
5
6
7
8
9
10
11
12
13
1>d:\documents\nihat\roughening\roughening\site.h(15): error C2143: syntax error : missing ';' before '*'
1>d:\documents\nihat\roughening\roughening\site.h(15): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\documents\nihat\roughening\roughening\site.h(15): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\documents\nihat\roughening\roughening\site.h(25): error C2061: syntax error : identifier 'systm'
1>d:\documents\nihat\roughening\roughening\site.h(28): error C2065: 'sys' : undeclared identifier
1>d:\documents\nihat\roughening\roughening\site.h(28): error C2065: 's' : undeclared identifier
1>d:\documents\nihat\roughening\roughening\site.h(33): error C2065: 'sys' : undeclared identifier
1>d:\documents\nihat\roughening\roughening\site.h(33): error C2227: left of '->getSize' must point to class/struct/union/generic type
1>          type is ''unknown-type''
1>d:\documents\nihat\roughening\roughening\site.h(35): error C2065: 'sys' : undeclared identifier
1>d:\documents\nihat\roughening\roughening\site.h(35): error C2227: left of '->getSite' must point to class/struct/union/generic type
1>          type is ''unknown-type''
1>d:\documents\nihat\roughening\roughening\systm.h(39): error C2661: 'site::site' : no overloaded function takes 2 arguments


Also another way to explain this.. When I comment out 16th line in 'site.h' and any other dependencies, I am not getting any of these errors on build. After a working build, I only added the 16th line, but I have the same errors.
Last edited on
Any help will be greatly appreciated..

Thank you
nobody could help you unless you post all of private header files here.:)
Since they are not the reasons of the error, and simple definitions, I thought posting them would not help, but here they are..

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
file_operations.h
#ifndef FILE_OPERATIONS_H
#define FILE_OPERATIONS_H

#include<stdio.h>

class file_operations
{
protected:
	FILE* file_id;
	char path[100];
public:
	void close() {fclose(file_id);}
	int exists(const char* path)
	{	
		if (FILE* fid = fopen(path, "r"))
		{
			fclose(fid);
			return 1;
		}
		return 0;
	}
};
#endif 


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
file_reader.h
#ifndef FILE_READER_H
#define FILE_READER_H

#include <string>

#include "file_operations.h"

class file_reader : public file_operations
{
public:
	// Constructor
	file_reader(const char* fname)
	{
		strcpy(path, fname);
		file_id = fopen(path, "r");
	}
};
#endif 


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
coordinates.h
#ifndef COORDINATES_H
#define COORDINATES_H

#include "site.h"

class coordinates
{
private:
	int x, y, z;
	int dim;
public:
	coordinates(int i, int j, int k)
	{
		x = i;
		y = j;
		z = k;
		dim = 3;
	}

	int getX(){return x;}
	int getY(){return y;}
	int getZ(){return z;}
	coordinates* getCoor(){return this;}
};
#endif 


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
35
36
37
38
39
40
timer.h
#ifndef TIMER_H
#define TIMER_H

#include <time.h>
#include <stdio.h>

class timer
{
private:
	time_t rawtime;
	struct tm* timeinfo;
public:
	timer()
	{
		time(&rawtime);
		timeinfo = localtime(&rawtime);
	}

	void restart()
	{
		time(&rawtime);
	}

	time_t getRawTime() {return rawtime;}
	const char* getPastTime(timer first)
	{
		char str[100];
		time_t raw = first.getRawTime();
		int diff = difftime(rawtime, raw);
		int hour = diff/(60*60);
		int min = (diff - hour*60)/60;
		int sec = diff%60;
		sprintf(str, "%d:%d:%d", hour, min, sec);
		return str;
	}

	const char* getTimeString() {return asctime(timeinfo);}
};
#endif 


dead end here.. I honestly don't know what to do..
I got it. your site.h and systm.h include each other. SITE_H or SYSTM_H block duplicated including, so at least one of them doesnt include the other .h file actually. bear in mind, let your compiler know where the definition of forward declaration class type is before you instantiate it or invoke it's any of method by pointer.
Thank you..!! :) You are a life saver.. :)
Topic archived. No new replies allowed.