This is my first post here, but I have been using the forum for many months and up untill now has been able to answer all my problems without me actually asking anything. So thanks in advance for all the great work you guys do, you have been fantastic in the past.
So, quick explanation. I have a class, called particle, which containts the function called Assign. Assign works perfectly where it is, but I want to move it. So after a bit of googling it seems the best way to do this is to use "::".
So in a new header simply write void particle::Assign(.....)
However I am getting error C2653: 'particle' : is not a class or namespace name. I do not know why, googling the error seems to suggest that the class "particle" does not exist. It does, it is right there.
I suspect I am doing something daft, and is easy and obvious to fix, but a good hour of searching and reading various past threads has not helped.
So, here is my code:
First the relevant bits of particle class, called particle2.h:
#include <math.h>
#include <vector>
#include <iostream>
#include <stdio.h>
#include "threevector.h"
#include "constants.h"
#include "initial_line.h"
using namespace std;
class particle
{
double x;
double y;
double z;
double q;
double m;
double ux;
double uy;
double uz;
double hux;
double huy;
double huz;
public:
particle()
{
x=0;
y=0;
z=0;
q=0;
m=0;
ux=0;
uy=0;
uz=0;
hux=0;
huy=0;
huz=0;
}
particle(double x, double y, double z, double q, double m, double ux, double uy, double uz, double hux, double huy, double huz)
{
this->x = x;
this->y = y;
this->z = z;
this->q = q; //charge
this->m = m; //mass
this->ux = ux; //initial speed
this->uy = uy; //initial speed
this->uz = uz; //initial speed
this->hux = hux; //previous half speed
this->huy = huy; //previous half speed
this->huz = huz; //previous half speed
}
void Assign(double, double, double, double, double, double, double, double, double, double, double);
double getx() const
{
return x;
}
double gety() const
{
return y;
}
double getz() const
{
return z;
}
double getm()
{
return m;
}
double getq()
{
return q;
}
double getux()
{
return ux;
}
double getuy()
{
return uy;
}
double getuz()
{
return uz;
}
double gethux()
{
return hux;
}
double gethuy()
{
return huy;
}
double gethuz()
{
return huz;
}
void setx(double x)
{
this->x = x;
}
void sety(double y)
{
this->y = y;
}
void setz(double z)
{
this->z = z;
}
void setux(double ux)
{
this->ux = ux;
}
void setuy(double uy)
{
this->uy = uy;
}
void setuz(double uz)
{
this->uz = uz;
}
void sethux(double hux)
{
this->hux = hux;
}
void sethuy(double huy)
{
this->huy = huy;
}
void sethuz(double huz)
{
this->huz = huz;
}
void setq(double q)
{
this->q = q;
}
void setm(double m)
{
this->m = m;
}
And here is the new header I have written, called initial_line.h:
#include "particle2.h"
using namespace std;
void particle::Assign(double x, double y, double z, double q, double m, double ux, double uy, double uz, double hux, double huy, double huz)
{
x = x / b0;
y = y / b0;
z = z / b0;
q = q / e;
m = m / me;
ux = ux / b0;
uy = uy / b0;
uz = uz / b0;
hux = hux / b0;
huy = huy / b0;
huz = huz / b0;
setx(x);
sety(y);
setz(z);
setq(q);
setm(m);
setux(ux);
setuy(uy);
setuz(uz);
sethux(hux);
sethuy(huy);
sethuz(huz);
}
particle 2.h is the file that the particle class is in.
So, the erros I get are
h:\treecode\treecode\initial_line.h(4) : error C2653: 'particle' : is not a class or namespace name
and then a load of errors for the set funtions eg.: 1>h:\treecode\treecode\initial_line.h(18) : error C3861: 'setx': identifier not found
I have tried various combinations of including and not including header files, and changing the names of the class and the funtion.
So, I am at a loss. It seems a simple enough concept that is just no working. I am using C++ within VS2008 pro, version 9. (Previous posts blamed errors in old compliers for problems)
So, I would be very grateful of any help, and to anyone pointing out what I have done wrong.
The funtion worked perfectly fine inside particle, and I assume all the errors involving the set funtions will go away onve it is properly linked with the particle class.
Cheers
Josh