#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    55
    Rep Power
    12

    pubic variable query


    I'm trying to debug a collision code tut and I thought that the best way would be to print variables to the screen so that I can see what values are passing. The function that prints to the screen (positionX is variable):


    // Set the window title bar to our string
    SetWindowText(g_hWnd, positionX);


    positionX is declared in header file:


    // This is our camera class
    class CCamera {

    public:

    // Our camera constructor
    CCamera();

    // These are are data access functions for our camera's private data
    CVector3 Position() { return m_vPosition; }
    CVector3 View() { return m_vView; }
    CVector3 UpVector() { return m_vUpVector; }
    CVector3 Strafe() { return m_vStrafe; }


    /////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *

    // This intializes the camera's sphere radius
    void SetCameraRadius(float radius) { m_radius = radius; };

    /////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *


    // This changes the position, view, and up vector of the camera.
    // This is primarily used for initialization
    void PositionCamera(float positionX, float positionY, float positionZ,
    float viewX, float viewY, float viewZ,
    float upVectorX, float upVectorY, float upVectorZ);


    Question is, if positionX is made public in the camera class, why do I get an undeclared error when I put it in the setWindowText function. Surely it's a public, so u can access it from any function? Thanks for help, ben
  2. #2
  3. No Profile Picture
    Mid-level Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    44
    Rep Power
    12

    Function outside class


    Is SetWindowText a function outside of the class CCamera?
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    55
    Rep Power
    12
    Yeah, it is, so does that mean I can't declare it? But I thought that's why u use public, so u can access the variable outside the class?
  6. #4
  7. No Profile Picture
    Mid-level Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    44
    Rep Power
    12

    Can be accessed


    Public does mean that you can access it from outside the class but it has to be done through an instance of the class. You are thinking of global variable (In C++, a variable with global scope). So you would have do something like:
    Code:
    CCamera c;
    .
    .
    .
    SetWindowText(.., c.postionX);
  8. #5
  9. not a fan of fascism (n00b)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Feb 2003
    Location
    ct
    Posts
    2,756
    Rep Power
    95
    heheheh he said "pubic variable"
    /me leaves computer and goes back to my 7th grade classroom
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    55
    Rep Power
    12
    Arg.... It's coming back at me now with:

    'positionX' : is not a member of 'CCamera'

    I guess it's because it's a variable in:

    void PositionCamera(float positionX, float positionY, float positionZ,
    float viewX, float viewY, float viewZ,
    float upVectorX, float upVectorY, float upVectorZ);

    Anyone know what now? (thanxs for help), ben
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    55
    Rep Power
    12
    I've tried:

    c.PositionCamera(positionX)

    but that doesn't work either.
  14. #8
  15. No Profile Picture
    Mid-level Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    44
    Rep Power
    12
    That won't work either PositionCamera doesn't only take one variable what you need it to write a function that returns positionX. Here is an example:

    Code:
    // This is our camera class 
    class CCamera { 
    
    float postionX;
    
    // notice the pass by reference
    void PositionCamera(float &positionX, float positionY, float positionZ, 
    float viewX, float viewY, float viewZ, 
    float upVectorX, float upVectorY, float upVectorZ); 
    
    float getPositionX(){ return positionX; }
    
    }
    Then you can do what I suggested before:

    Code:
    CCamera c;
    .
    .
    SetWindowText(g_hWnd, c.getPostionX() );
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    55
    Rep Power
    12
    Thanks, you're the man!

IMN logo majestic logo threadwatch logo seochat tools logo