Static Objects

Hi guys

This will be a small post since I only received on error message:

...\C++\RunningMan\CPlayer.cpp|208|error: 'class CCamera' has no member named 'SetPosition'|
||=== Build finished: 1 errors, 4 warnings (0 minutes, 0 seconds) ===|


I have a static object of the CCamera-class declared in CCamera-class ^^

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#ifndef _CCAMERA_H_
    #define _CCAMERA_H_

#include "SDL.h"
#include <iostream>


class CGame;


class CCamera
{
    public:
        static CCamera Camera; //Here s the culprit
        CCamera();

        void SetPosX(float MovementSpeed);
        float GetPosX();
        float GetPosY();

        SDL_Rect Viewport;

    private:
        float m_PosX;
        float m_PosY;
        float m_Width;
        float m_Height;

};





#endif // _CCAMERA_H_ 


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include "CCamera.h"


CCamera CCamera::Camera; //Maybe someone helping the culprit ? :P


CCamera::CCamera()
{
    m_PosX = 0;
    m_PosY = 0;
    m_Width = 640;
    m_Height = 480;

    Viewport.x = m_PosX;
    Viewport.y = m_PosY;
    Viewport.w = m_Width;
    Viewport.h = m_Height;
}

void CCamera::SetPosX(float MovementSpeed)
{
    m_PosX += MovementSpeed;
    Viewport.x = m_PosX;
}

float CCamera::GetPosX()
{
    return m_PosX;
}

float CCamera::GetPosY()
{
    return m_PosY;
}


Could anyone explain me why I can't do the following thing in CPlayer-class:
 
CCamera::Camera.SetCamera(-5);
This is a bit confusing because the error message says CCamera does not have a function named SetPosition which must mean you are trying to call SetPosition on a CCamera object somewhere in your code. You also mention a function SetCamera which is another function that CCamera does not have.
Wow Its fixed thanks :))
Topic archived. No new replies allowed.