Jump to content
  • Advertisement
Sign in to follow this  
shadone

c++ neverending declaration problem..

This topic is 3352 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
BTW
i have omitted some other parts for the sake of simplicity, since my problem is about this declaration part of the scene class.

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
I put the following exact source code in a file and it compiles:


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++.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Do you have something of the form:

class Foo
{
Bar::Bar() : x_(), y_(), z_() {}
};


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!