c++ neverending declaration problem..
Hi there..
first of all, i have been working with c++ for 1 month and i have a huge gap in my background about this language..
anyways, i have a never ending declaration problem in one side and for a long time im not doing anything but trying to solve this problem.. i think i need help at this point..
here im posting the code i've written and the problem:
//scene.h
class Scene{
public:
Scene();
Scene(Camera* c, Sampler* s);
//bool intersect(Ray& ray, Intersection* intersect);
void render();
Radiance l(const Ray&);
private:
Camera* camera_;
Sampler* sample_;
Screen* screen_;
Radiance **buffer;
double screenSize;
};
//scene.cpp
Scene::Scene(){
screen_ = new Screen(300,300);
sample_ = new Sampler(12,12,-5,screen_);
camera_ = new Camera(Vector3D(0,0,-20),Vector3D(0,0,1));
}
Scene::Scene(Camera *c, Sampler *s) : camera_(c),sample_(s){
};
//and the error is:
error C3254: 'Sampler' : class contains explicit override '{ctor}' but does not derive from an interface that contains the function declaration
error C2838: '{ctor}' : illegal qualified name in member declaration
error C2590: '{ctor}' : only a constructor can have a base/member initializer list
this error msg is actually for all the objects im trying to create, ie. for Sampler, Camera and Screen.
how can i fix the problem?
BTW
i have omitted some other parts for the sake of simplicity, since my problem is about this declaration part of the scene class.
i have omitted some other parts for the sake of simplicity, since my problem is about this declaration part of the scene class.
Hi,
Yes, but the error is about Sampler and you don't show that code.
(You might want to check that the name of the constructor of Sampler exactly matches the name of the class and no CSampler::CSampler or anything in the class itself)
Yes, but the error is about Sampler and you don't show that code.
(You might want to check that the name of the constructor of Sampler exactly matches the name of the class and no CSampler::CSampler or anything in the class itself)
i see what you mean, here im pasting my Sampler class as well:
// Sampler.h
class Sampler {
public:
Sampler (double width, double height, float z, Screen* scr) :width_(width),height_(height),z_(z),scr_(scr){
};
double width() {return width_;};
double height() {return height_;};
Screen* screen() {return scr_;};
private:
double width_;
double height_;
float z_;
Screen* scr_;
};
ok and the Screen class:
//screen.h
class Screen {
public:
Screen (double width = 300, double height = 300) :w_(width), h_(height){
};
};
actually i don't understand the meaning of the error, what is that {cotr} stuff? how can i prevent this? is it about using "const" term in the classes? if so, how can i use that?
// Sampler.h
class Sampler {
public:
Sampler (double width, double height, float z, Screen* scr) :width_(width),height_(height),z_(z),scr_(scr){
};
double width() {return width_;};
double height() {return height_;};
Screen* screen() {return scr_;};
private:
double width_;
double height_;
float z_;
Screen* scr_;
};
ok and the Screen class:
//screen.h
class Screen {
public:
Screen (double width = 300, double height = 300) :w_(width), h_(height){
};
};
actually i don't understand the meaning of the error, what is that {cotr} stuff? how can i prevent this? is it about using "const" term in the classes? if so, how can i use that?
too many semi-colons! [smile]
You don't need a semi colon after the curly braces of function definitions.
You don't need a semi colon after the curly braces of function definitions.
Quote:Original post by shadone
actually i don't understand the meaning of the error, what is that {cotr} stuff? how can i prevent this? is it about using "const" term in the classes? if so, how can i use that?
ctor is short for constructor
I put the following exact source code in a file and it compiles:
1) Does that work for you? If so, try adding the other things back until you find the problem.
2) Exactly what language do you think you are using here? And exactly how are you compiling it? Visual Studio understands a few variants that are not really C++.
class Sampler {public:Sampler (double width, double height, float z/*, Screen* scr*/) :width_(width),height_(height),z_(z)/*,scr_(scr)*/{};double width() {return width_;};double height() {return height_;};//Screen* screen() {return scr_;};private:double width_;double height_;float z_;//Screen* scr_;};class Scene{public:Scene();Scene(/*Camera* c,*/ Sampler* s);//bool intersect(Ray& ray, Intersection* intersect);void render();//Radiance l(const Ray&);private://Camera* camera_;Sampler* sample_;//Screen* screen_;//Radiance **buffer;double screenSize;};Scene::Scene(){//screen_ = new Screen(300,300);sample_ = new Sampler(12,12,-5/*,screen_*/);//camera_ = new Camera(Vector3D(0,0,-20),Vector3D(0,0,1));}Scene::Scene(/*Camera *c,*/ Sampler *s) : /*camera_(c),*/sample_(s){};int main() { Scene s;}
1) Does that work for you? If so, try adding the other things back until you find the problem.
2) Exactly what language do you think you are using here? And exactly how are you compiling it? Visual Studio understands a few variants that are not really C++.
The compiler seems to recognize Sampler as a class but also seems to see an explicit overide somewhere i.e. somtething int the form baseclass::functionname
It seems pretty confused since the name it prints seems to be some internal name.
I think you need to post the complete header (you do have guards against multiple inclusion I assume, so this is not the complete header?) and the headers it includes.
Do all the '{' matches with '}' In VS you can use the control key with the square bracket to jump between brackets of the same level. Use Control-K F to 'C beautify' your code.
It seems pretty confused since the name it prints seems to be some internal name.
I think you need to post the complete header (you do have guards against multiple inclusion I assume, so this is not the complete header?) and the headers it includes.
Do all the '{' matches with '}' In VS you can use the control key with the square bracket to jump between brackets of the same level. Use Control-K F to 'C beautify' your code.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement