invalid conversion

A

Andrew Poelstra

Hi
aren't those two pointers? What is my fault?
Thanks Michael

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.
 
R

Robert Fendt

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
 
R

red floyd

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.
 
P

Paul N

What do you mean?

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.
 
M

mickCyber

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;
}
 
J

Jonathan Lee

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
 
M

mickCyber

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)’
 
M

Michael Doubez

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’


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

mickCyber

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)
 
M

Michael Doubez

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);
}
 
M

mickCyber

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
 
M

Michael Doubez

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.
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top