does not have class type C++

前端 未结 4 948
眼角桃花
眼角桃花 2021-02-02 13:28

This is one class from my program! When I\'m trying to compile the whole program, I get an error message like this:

main.cpp:174: error: \'((Scene*)this)

4条回答
  •  -上瘾入骨i
    2021-02-02 14:11

    Your problem is in the following line:

    Lake lake(int L);
    

    If you're just trying to declare a Lake object then you probably want to remove the (int L). What you have there is declaring a function lake that returns a Lake and accepts an int as a parameter.

    If you're trying to pass in L when constructing your lake object, then I think you want your code to look like this:

    class Scene
    {
        int L,Dist;
        Background back ;
        Lake lake;
        IceSkater iceskater;
    public :
        Scene(int L, int Dist) :
            L(L),     
            Dist(Dist),
            lake(L),
            iceskater(Dist)
        {
            cout<<"Scene was just created"<

    Notice the 4 lines added to your constructor. This is called member initialization, and its how you construct member variables. Read more about it in this faq. Or some other tidbits I found here and here.

提交回复
热议问题