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..
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 = newint*[2*d];
for (int i = 0; i<2*d; i++)
spin[i] = newint[(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.
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(){returnthis;}
};
#endif
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.