invalid conversion

Discussion in 'C++' started by mickCyber, Mar 18, 2010.

  1. mickCyber

    mickCyber Guest

    Hi
    aren't those two pointers? What is my fault?
    Thanks Michael
    ------
    invalid conversion from ‘void*’ to
    ‘OpenGLWaveFrontMaterial::VertexTextureIndex*
     
    mickCyber, Mar 18, 2010
    #1
    1. Advertising

  2. On 2010-03-18, mickCyber <> wrote:
    > Hi
    > aren't those two pointers? What is my fault?
    > Thanks Michael
    > ------
    > invalid conversion from ‘void*’ to
    > ‘OpenGLWaveFrontMaterial::VertexTextureIndex*


    They're both pointers, sure, but that doesn't make them the same type.
    I'm not sure what you're trying to do, but you're doing it wrong -
    in C you can implicitly convert void * to any other kind of pointer
    but this is not possible in C++.

    In any case, them "both being pointers" is not relevant.

    --
    Andrew Poelstra
    http://www.wpsoftware.net/andrew
     
    Andrew Poelstra, Mar 18, 2010
    #2
    1. Advertising

  3. mickCyber

    Mike Guest

    Mike, Mar 19, 2010
    #3
  4. mickCyber

    Robert Fendt Guest

    And thus spake Mike <>
    Fri, 19 Mar 2010 03:44:59 -0700 (PDT):

    > Thanks for further help


    Without at least a few lines of the code that actually produces
    the error message, further help will be more or less impossible.

    Regards,
    Robert
     
    Robert Fendt, Mar 19, 2010
    #4
  5. mickCyber

    red floyd Guest

    On Mar 19, 9:47 am, Robert Fendt <> wrote:
    > And thus spake Mike <>
    > Fri, 19 Mar 2010 03:44:59 -0700 (PDT):
    >
    > > Thanks for further help

    >
    > Without at least a few lines of the code that actually produces
    > the error message, further help will be more or less impossible.


    I'm going to assume that OpenGlWaveFrontMaterial::VertexTextureIndex*
    is a pointer to member,
    and he's trying to convert from a void* to that.

    However, as always, FAQ 5.8 applies.
     
    red floyd, Mar 19, 2010
    #5
  6. mickCyber

    mickCyber Guest

    What do you mean?
    > However, as always, FAQ 5.8 applies.


    First error here in the code:
    VertexTextureIndex *ret = malloc(sizeof(VertexTextureIndex));
     
    mickCyber, Mar 20, 2010
    #6
  7. mickCyber

    Paul N Guest

    On 20 Mar, 07:01, mickCyber <> wrote:
    > What do you mean?
    >
    > > However, as always, FAQ 5.8 applies.


    The "FAQ" is a list of Frequntly Asked Questions. You can find the FAQ
    at http://www.parashift.com/c -faq-lite/ or it's the first hit if you
    type "c++ faq" into Google. It's recommended that you read it all.

    FAQ 5.8 gives information about how to ask for help, which you don't
    appear to have followed.

    > First error here in the code:
    >         VertexTextureIndex *ret = malloc(sizeof(VertexTextureIndex));


    malloc returns a pointer to void. In C++, to convert this to a pointer
    to some other type, you have to use a cast. For example,

    VertexTextureIndex *ret = (VertexTextureIndex *)
    malloc(sizeof(VertexTextureIndex));

    Alternatively, you could use "new" instead, which would give certain
    advantages (such as running an appropriate constructor, and getting
    type safety without needing a cast) but would require certain other
    changes (eg needing "delete" instead of "free"). See FAQ 16.4 for
    more...

    (Note that in C the cast is not required, and it is considered (at
    least by some!) good practice not to use it.)

    Hope this helps.
    Paul.
     
    Paul N, Mar 20, 2010
    #7
  8. mickCyber

    mickCyber Guest

    Thanks Paul now i get three lines before end at:
    GLuint greaterIndex =
    ------
    Multiple markers at this line
    - invalid conversion from ‘void*’ to
    ‘OpenGLWaveFrontMaterial::VertexTextureIndex*’
    - initializing argument 1 of ‘static GLuint
    OpenGLWaveFrontMaterial::VertexTextureIndexMatch(OpenGLWaveFrontMaterial::VertexTextureIndex*,
    GLuint,
    ------



    // An actualVertex value of UINT_MAX means that the actual integer value
    hasn't been determined yet.
    typedef struct {
    GLuint originalVertex;
    GLuint textureCoords;
    GLuint actualVertex;
    void *greater;
    void *lesser;

    } VertexTextureIndex;
    static inline VertexTextureIndex * VertexTextureIndexMake (GLuint
    inVertex, GLuint inTextureCoords, GLuint inActualVertex)
    {
    VertexTextureIndex *ret = new VertexTextureIndex;
    //1 of Paul see above VertexTextureIndex *ret = (VertexTextureIndex *)
    malloc(sizeof(VertexTextureIndex));
    //orig of Paul see above VertexTextureIndex *ret =
    malloc(sizeof(VertexTextureIndex));
    ret->originalVertex = inVertex;
    ret->textureCoords = inTextureCoords;
    ret->actualVertex = inActualVertex;
    ret->greater = NULL;
    ret->lesser = NULL;
    return ret;
    }
    #define VertexTextureIndexMakeEmpty(x,y) VertexTextureIndexMake(x, y,
    UINT_MAX)
    // recursive search function - looks for a match for a given combination
    of vertex and
    // texture coordinates. If not found, returns UINT_MAX
    static inline GLuint VertexTextureIndexMatch(VertexTextureIndex *node,
    GLuint matchVertex, GLuint matchTextureCoords)
    {
    if (node->originalVertex == matchVertex && node->textureCoords ==
    matchTextureCoords)
    return node->actualVertex;

    if (node->greater != NULL)
    {
    GLuint greaterIndex = VertexTextureIndexMatch(node->greater,
    matchVertex, matchTextureCoords);
    if (greaterIndex != UINT_MAX)
    return greaterIndex;
    }


    ----------
    As you can see i used new but thanks again for the second error.
    Michael
     
    mickCyber, Mar 21, 2010
    #8
  9. mickCyber

    Jonathan Lee Guest

    On Mar 21, 11:57 am, mickCyber <> wrote:
    > Thanks Paul now i get three lines before end at:


    This is basically the exact same error. You are passing node->greater,
    which is of type void*, to VertexTextureIndexMatch which is expecting
    a VertexTextureIndex*.

    Either cast node->greater to the correct type, or change the "greater"
    member of VertexTextureIndex to be of the correct type.

    While we're at it, that whole function VertexTextureIndexMake() is a
    little weird. Why wouldn't you just make this a constructor of
    VertexTextureIndex?

    Finally, returning a pointer just introduces memory management
    headaches. You're going to have to keep track of that pointer and
    delete it somewhere else. In C++ you'd usually use a container
    class to handle that for you. Or even pass things around by value
    instead of pointer.

    --Jonathan
     
    Jonathan Lee, Mar 21, 2010
    #9
  10. mickCyber

    mickCyber Guest

    Thanks Jonathan
    changed the code a bit. Better so?


    typedef struct {
    void *VertexTextureIndexMakeEmpty(int x,int y);
    void *VertexTextureIndexMake(int x, int y, int UINT_MAX);
    GLuint originalVertex;
    GLuint textureCoords;
    GLuint actualVertex;
    void *greater;
    void *lesser;

    } VertexTextureIndex;

    VertexTextureIndex::VertexTextureIndexMake (GLuint inVertex, GLuint
    inTextureCoords, GLuint inActualVertex)
    //static inline VertexTextureIndex * VertexTextureIndexMake (GLuint
    inVertex, GLuint inTextureCoords, GLuint inActualVertex)
    {
    VertexTextureIndex *ret = new VertexTextureIndex;
    //1 VertexTextureIndex *ret = (VertexTextureIndex *)
    malloc(sizeof(VertexTextureIndex));
    //2 VertexTextureIndex *ret = malloc(sizeof(VertexTextureIndex));
    ret->originalVertex = inVertex;
    ret->textureCoords = inTextureCoords;
    ret->actualVertex = inActualVertex;
    ret->greater = NULL;
    ret->lesser = NULL;
    return ret;
    }
    //#define VertexTextureIndexMakeEmpty(x,y) VertexTextureIndexMake(x, y,
    UINT_MAX)
    // recursive search function - looks for a match for a given combination
    of vertex and
    // texture coordinates. If not found, returns UINT_MAX
    static inline GLuint VertexTextureIndexMatch(VertexTextureIndex *node,
    GLuint matchVertex, GLuint matchTextureCoords)
    {
    if (node->originalVertex == matchVertex && node->textureCoords ==
    matchTextureCoords)
    return node->actualVertex;

    if (node->greater != NULL)
    {
    GLuint greaterIndex = VertexTextureIndexMatch(node->greater,
    matchVertex, matchTextureCoords);


    ----------
    after the struct (next line) I get this error:


    Multiple markers at this line
    - Syntax error
    - ISO C++ forbids declaration of ‘VertexTextureIndexMake’ with no type
    - cannot define member function
    ‘OpenGLWaveFrontMaterial::VertexTextureIndex::VertexTextureIndexMake’
    within
    ‘OpenGLWaveFrontMaterial’


    ------
    and on the final line still the same error as I don't know how to change
    greater's type:


    Multiple markers at this line
    - invalid conversion from ‘void*’ to
    ‘OpenGLWaveFrontMaterial::VertexTextureIndex*’
    - initializing argument 1 of ‘static GLuint
    OpenGLWaveFrontMaterial::VertexTextureIndexMatch(OpenGLWaveFrontMaterial::VertexTextureIndex*,
    GLuint,
    GLuint)’


    ---
    thanks again
    Michael
     
    mickCyber, Mar 22, 2010
    #10
  11. On 22 mar, 09:59, mickCyber <> wrote:
    > Thanks Jonathan
    > changed the code a bit. Better so?


    Depends. If you want to make C++ code, drop the C constructs.

    > typedef struct {


    Use directly:
    struct VertexTextureIndex {

    >         void *VertexTextureIndexMakeEmpty(int x,int y);
    >         void *VertexTextureIndexMake(int x, int y, int UINT_MAX);
    >         GLuint  originalVertex;
    >         GLuint  textureCoords;
    >         GLuint  actualVertex;
    >         void    *greater;
    >         void    *lesser;
    >


    } ;

    >
    > VertexTextureIndex::VertexTextureIndexMake (GLuint inVertex, GLuint
    > inTextureCoords, GLuint inActualVertex)
    > //static inline VertexTextureIndex * VertexTextureIndexMake (GLuint
    > inVertex, GLuint inTextureCoords, GLuint inActualVertex)


    You didn't respect the signature:
    void*
    VertexTextureIndex::VertexTextureIndexMake(int x, int y, int
    UINT_MAX);
    > {
    >         VertexTextureIndex *ret = new VertexTextureIndex;
    > //1     VertexTextureIndex *ret = (VertexTextureIndex *)
    > malloc(sizeof(VertexTextureIndex));
    > //2     VertexTextureIndex *ret = malloc(sizeof(VertexTextureIndex));
    >         ret->originalVertex = inVertex;
    >         ret->textureCoords = inTextureCoords;
    >         ret->actualVertex = inActualVertex;
    >         ret->greater = NULL;
    >         ret->lesser = NULL;
    >         return ret;}


    Why do you return a void* if you intent to return a
    VertexTextureIndex* ?

    >
    > //#define VertexTextureIndexMakeEmpty(x,y) VertexTextureIndexMake(x, y,
    > UINT_MAX)
    > // recursive search function - looks for a match for a given combination
    > of vertex and
    > // texture coordinates. If not found, returns UINT_MAX
    > static inline GLuint VertexTextureIndexMatch(VertexTextureIndex *node,
    > GLuint matchVertex, GLuint matchTextureCoords)
    > {
    >         if (node->originalVertex == matchVertex && node->textureCoords ==
    > matchTextureCoords)
    >                 return node->actualVertex;
    >
    >         if (node->greater != NULL)
    >         {
    >                 GLuint greaterIndex = VertexTextureIndexMatch(node->greater,
    > matchVertex, matchTextureCoords);



    VertexTextureIndexMatch() is expecting a VertexTextureIndex* as its
    first parameter; node->greater is void*.

    You could make greater and lesser VertexTextureIndex*.

    >
    > ----------
    > after the struct (next line) I get this error:
    >
    > Multiple markers at this line
    >         - Syntax error
    >         - ISO C++ forbids declaration of ‘VertexTextureIndexMake’ with no type
    >         - cannot define member function
    > ‘OpenGLWaveFrontMaterial::VertexTextureIndex::VertexTextureIndexMake’
    > within
    >          ‘OpenGLWaveFrontMaterial’
    >
    > ------
    > and on the final line still the same error as I don't know how to change
    > greater's type:



    Easy to change:
    struct VertexTextureIndex {
    // ...
    VertexTextureIndex* greater;
    VertexTextureIndex* lesser;
    };

    >
    > Multiple markers at this line
    >         - invalid conversion from ‘void*’ to
    > ‘OpenGLWaveFrontMaterial::VertexTextureIndex*’
    >         - initializing argument 1 of ‘static GLuint
    > OpenGLWaveFrontMaterial::VertexTextureIndexMatch(OpenGLWaveFrontMaterial::VertexTextureIndex*,
    > GLuint,
    >          GLuint)’


    --
    Michael
     
    Michael Doubez, Mar 22, 2010
    #11
  12. mickCyber

    mickCyber Guest

    Thanks Michael

    pragma is C specific? what about #define at the bottom? I've commented
    that line and defined in struct VertexTextureIndex. Correct? Well
    later on I get an error that
    "VertexTextureIndexMakeEmpty‘VertexTextureIndexMakeEmpty’ was not
    declared in this scope"
    Those structs are inside another class, ok in C++?
    Thanks again




    #pragma mark -
    #pragma mark VertexTextureCombinations
    #pragma mark -

    struct VertexTextureIndex {
    void *VertexTextureIndexMakeEmpty(int x,int y);
    void *VertexTextureIndexMake(int x, int y, int UINT_MAX);
    GLuint originalVertex;
    GLuint textureCoords;
    GLuint actualVertex;
    VertexTextureIndex *greater;
    VertexTextureIndex *lesser;
    };

    //void *VertexTextureIndex::VertexTextureIndexMake(int x, int y, int
    UINT_MAX)
    //void *VertexTextureIndex::VertexTextureIndexMake (GLuint inVertex,
    GLuint inTextureCoords, GLuint inActualVertex)
    static inline VertexTextureIndex * VertexTextureIndexMake (GLuint
    inVertex, GLuint inTextureCoords, GLuint inActualVertex)
    {
    VertexTextureIndex *ret = new VertexTextureIndex;
    //1 VertexTextureIndex *ret = (VertexTextureIndex *)
    malloc(sizeof(VertexTextureIndex));
    //2 VertexTextureIndex *ret = malloc(sizeof(VertexTextureIndex));
    ret->originalVertex = inVertex;
    ret->textureCoords = inTextureCoords;
    ret->actualVertex = inActualVertex;
    ret->greater = NULL;
    ret->lesser = NULL;
    return ret;
    }
    //#define VertexTextureIndexMakeEmpty(x,y) VertexTextureIndexMake(x, y,
    UINT_MAX)
     
    mickCyber, Mar 22, 2010
    #12
  13. On 22 mar, 13:00, mickCyber <> wrote:
    > Thanks Michael
    >
    > pragma is C specific?


    No. But what is does is usually compiler specific.

    > what about #define at the bottom?


    Avoid macros, especially when the name is not in upper case.

    > I've commented
    > that line and defined in struct VertexTextureIndex. Correct? Well
    > later on I get an error that
    > "VertexTextureIndexMakeEmpty‘VertexTextureIndexMakeEmpty’ was not
    > declared in this scope"


    You first declared it as a member function an then as a free function.
    The naming is a follow:
    class Foo
    { public:
    void bar();
    };

    void Foo::bar()
    {
    // implementation
    }


    > Those structs are inside another class, ok in C++?


    I don't understand this sentence.

    > Thanks again
    >
    > #pragma mark -
    > #pragma mark VertexTextureCombinations
    > #pragma mark -
    >
    > struct VertexTextureIndex {
    >         void *VertexTextureIndexMakeEmpty(int x,int y);
    >         void *VertexTextureIndexMake(int x, int y, int UINT_MAX);


    You mean:
    static VertexTextureIndex* MakeEmpty(GLuint x,GLuint y);
    static VertexTextureIndex* Make(GLuint x,GLuint y,GLuint z);


    >         GLuint  originalVertex;
    >         GLuint  textureCoords;
    >         GLuint  actualVertex;
    >         VertexTextureIndex      *greater;
    >         VertexTextureIndex      *lesser;
    >
    > };
    >

    [snip]

    VertexTextureIndex*
    VertexTextureIndex::Make ( GLuint inVertex
    , GLuint inTextureCoords
    , GLuint inActualVertex)
    > {
    >         VertexTextureIndex *ret = new VertexTextureIndex;

    [snip]
    >         ret->originalVertex = inVertex;
    >         ret->textureCoords = inTextureCoords;
    >         ret->actualVertex = inActualVertex;
    >         ret->greater = NULL;
    >         ret->lesser = NULL;
    >         return ret;}



    VertexTextureIndex*
    VertexTextureIndex::MakeEmpty ( GLuint inVertex
    , GLuint inTextureCoords)
    {
    return Make(inVertex,inTextureCoords,UINT_MAX);
    }

    Note that I assumed you didn't want to define a constructor in order
    to keep VertexTextureIndex PODness. In fact, you could certainly
    define a constructor and most compilers will still consider it a POD.

    It would simplify the code a lot:
    VertexTextureIndex::VertexTextureIndex(GLuint inVertex
    , GLuint inTextureCoords
    , GLuint inActualVertex = UINT_MAX)
    : originalVertex(inVertex)
    , textureCoords (inTextureCoords )
    , actualVertex ( inActualVertex )
    , greater()
    , lesser ()
    { /* NOP */ }

    VertexTextureIndex*
    VertexTextureIndex::Make ( GLuint inVertex
    , GLuint inTextureCoords
    , GLuint inActualVertex)
    {
    return new
    VertexTextureIndex(inVertex,inTextureCoords,inActualVertex);
    }

    VertexTextureIndex*
    VertexTextureIndex::MakeEmpty ( GLuint inVertex
    , GLuint inTextureCoords)
    {
    return new VertexTextureIndex(inVertex,inTextureCoords);
    }


    --
    Michael
     
    Michael Doubez, Mar 22, 2010
    #13
  14. mickCyber

    mickCyber Guest

    Many thanks Michael now it looks so:
    -------


    class VertexTextureIndex {
    public:
    VertexTextureIndex(GLuint inVertex, GLuint inTextureCoords, GLuint
    UINT_MAX);
    ~VertexTextureIndex();
    static VertexTextureIndex* MakeEmpty(GLuint x,GLuint y);
    static VertexTextureIndex* Make(GLuint x,GLuint y,GLuint z);
    // void *VertexTextureIndexMakeEmpty(int x,int y);
    // void *VertexTextureIndexMake(int x, int y, int UINT_MAX);
    GLuint originalVertex;
    GLuint textureCoords;
    GLuint actualVertex;
    VertexTextureIndex *greater;
    VertexTextureIndex *lesser;
    };

    VertexTextureIndex::VertexTextureIndex(GLuint inVertex, GLuint
    inTextureCoords, GLuint inActualVertex = UINT_MAX);
    {
    originalVertex(inVertex);
    textureCoords (inTextureCoords );
    actualVertex ( inActualVertex );
    greater();
    lesser ();
    }

    //void *VertexTextureIndex::VertexTextureIndexMake(int x, int y, int
    UINT_MAX)
    //void *VertexTextureIndex::VertexTextureIndexMake (GLuint inVertex,
    GLuint inTextureCoords, GLuint inActualVertex)
    VertexTextureIndex* VertexTextureIndex::Make(GLuint inVertex, GLuint
    inTextureCoords, GLuint inActualVertex)
    {


    ------------
    In the middle at: VertexTextureIndex::VertexTextureIndex I get:
    cannot declare member function
    ‘OpenGLWaveFrontMaterial::VertexTextureIndex::VertexTextureIndex’ within
    ‘OpenGLWaveFrontMaterial’

    and on the last line:
    cannot define member function
    ‘OpenGLWaveFrontMaterial::VertexTextureIndex::Make’ within
    ‘OpenGLWaveFrontMaterial’

    Many thanks again
     
    mickCyber, Mar 23, 2010
    #14
  15. On 23 mar, 12:57, mickCyber <> wrote:
    > Many thanks Michael now it looks so:
    > -------
    >
    > class VertexTextureIndex {
    > public:
    >         VertexTextureIndex(GLuint inVertex, GLuint inTextureCoords, GLuint
    > UINT_MAX);


    You mean:
    VertexTextureIndex(GLuint inVertex, GLuint inTextureCoords,
    GLuint inActualVertex = UINT_MAX);


    >         ~VertexTextureIndex();
    >     static VertexTextureIndex* MakeEmpty(GLuint x,GLuint y);
    >     static VertexTextureIndex* Make(GLuint x,GLuint y,GLuint z);
    > //      void *VertexTextureIndexMakeEmpty(int x,int y);
    > //      void *VertexTextureIndexMake(int x, int y, int UINT_MAX);
    >         GLuint  originalVertex;
    >         GLuint  textureCoords;
    >         GLuint  actualVertex;
    >         VertexTextureIndex      *greater;
    >         VertexTextureIndex      *lesser;
    >
    > };
    >


    This is not good. Look at the code I posted on the constructor.

    >         VertexTextureIndex::VertexTextureIndex(GLuint inVertex, GLuint
    > inTextureCoords, GLuint inActualVertex = UINT_MAX);
    >         {
    >         originalVertex(inVertex);
    >         textureCoords (inTextureCoords );
    >         actualVertex  ( inActualVertex );
    >         greater();
    >         lesser ();
    >         }
    >

    [snip]
    > VertexTextureIndex* VertexTextureIndex::Make(GLuint inVertex, GLuint
    > inTextureCoords, GLuint inActualVertex)
    > {
    >
    > ------------
    > In the middle at: VertexTextureIndex::VertexTextureIndex I get:
    > cannot declare member function
    > ‘OpenGLWaveFrontMaterial::VertexTextureIndex::VertexTextureIndex’ within
    > ‘OpenGLWaveFrontMaterial’
    >
    > and on the last line:
    > cannot define member function
    > ‘OpenGLWaveFrontMaterial::VertexTextureIndex::Make’ within
    > ‘OpenGLWaveFrontMaterial’
    >
    > Many thanks again



    I think you should learn at least the basics of C++ (such as the
    syntax).

    I won't spend any more time on this thread.

    --
    Michael
     
    Michael Doubez, Mar 23, 2010
    #15
  16. mickCyber

    mickCyber Guest

    mickCyber, Mar 25, 2010
    #16
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tim Johansson
    Replies:
    15
    Views:
    8,403
    Christopher Benson-Manica
    Apr 8, 2004
  2. Patrick.O.Ige
    Replies:
    1
    Views:
    2,021
    Patrick.O.Ige
    Jul 2, 2006
  3. Java Guy
    Replies:
    1
    Views:
    716
    Manish Pandit
    Oct 15, 2006
  4. kevin
    Replies:
    0
    Views:
    1,041
    kevin
    Jan 16, 2008
  5. Java Guy
    Replies:
    1
    Views:
    337
Loading...

Share This Page