pointer / deltaTime in OpenGL Game Programming book

Discussion in 'C++' started by Michael Sgier, Sep 9, 2005.

  1. Hello
    I've a function like:

    extern CModelMD3 *pModel;
    gameCamera->MoveTo(* pModel);

    which returns:
    no matching function for call to `CCamera::MoveTo(CModelMD3&)

    but in camera.h i've:
    void MoveTo(CObject *object);

    and in camera.cpp:
    void CCamera::MoveTo(CObject *object)
    {
    ....
    }

    The modelclass is like:
    class CModelMD3 : public CObject

    I might have missunderstood something here as I'm new to pointers?
    Secondly in the book
    OpenGL Game Programming there's in the engine example often deltaTime. I
    can't find
    any definition/declaration. It has random values like 286 but as far as
    I've seen always
    around 250-350. it's used like position = velocity + deltaTime
    What is it? Where is deltaTime defined? How could i use / exchange
    deltaTime in Linux/Mac.
    THANKS and regards
    Michael
     
    Michael Sgier, Sep 9, 2005
    #1
    1. Advertisements

  2. Michael Sgier

    int2str Guest

    The second line shoult be:
    gameCamera->MoveTo(pModel);

    The function takes a pointer as it's argument. Passing "*pModel" means
    you're dereferencing the pointer first before passing it - meaning
    you'll try to pass the actual object and not the pointer to it.

    Cheers,
    Andre
     
    int2str, Sep 9, 2005
    #2
    1. Advertisements

  3. As the compiler tells you: There is no function taking an object or a reference
    to an object. There is only a function taking a pointer.

    If you have a pointer
    extern CModelMD3 *pModel;

    the applying the dereference operator on it, as in *pModel
    lets you request the object where the pointer points to.

    MoveTo wants a pointer, you have a pointer, thus:

    gameCamera->MoveTo( pModel);
     
    Karl Heinz Buchegger, Sep 9, 2005
    #3
  4. Hello
    thanks for you answers. Well if i do so:

    extern CCamera* gameCamera;
    extern CModelMD3 *pModel;
    gameCamera->MoveTo(pModel);

    i get:
    undefined reference to `gameCamera'

    which is defined/declared exactly like CModelMD3.
    THANKS and regards
    Michael
     
    Michael Sgier, Sep 9, 2005
    #4
  5. Michael Sgier

    Howard Guest

    Changing the parameter to the function MoveTo wouldn't affect whether
    gameCamera is defined or not, and that change was the correct thing to do.

    Is the error a compile error, or a link error? Is gameCamera actually
    defined somewhere else? (That's what the "extern" specifier says.) Do you
    include camera.h in this file? (Also, is gameCamera initialized somewhere?)

    I'm also wondering where this code you've shown resides. You've got an
    extern declaration, and apparently follow it immediately with a function
    call. That's pretty strange. Usually extern declarations are made in the
    global scope, either before any functions in a cpp file, or in an included
    header file. What's the _real_ code look like?

    Perhaps you don't need pointers or extern declarations at all, but just
    local object declarations, or member declarations? It's impossible to tell
    with the little code you've shown, though.

    -Howard
     
    Howard, Sep 9, 2005
    #5
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.