Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > invalid conversion

Reply
Thread Tools

invalid conversion

 
 
mickCyber
Guest
Posts: n/a
 
      03-18-2010
Hi
aren't those two pointers? What is my fault?
Thanks Michael
------
invalid conversion from ‘void*’ to
‘OpenGLWaveFrontMaterial::VertexTextureIndex*
 
Reply With Quote
 
 
 
 
Andrew Poelstra
Guest
Posts: n/a
 
      03-18-2010
On 2010-03-18, mickCyber <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
 
Mike
Guest
Posts: n/a
 
      03-19-2010
Hi Andrew
yea C++. I try to use this:
http://iphonedevelopment.blogspot.co...rt-script.html
within my C++/Eclipse/Linux application. In fact only showing a
textured mesh from Blender
in my code but turns out pretty complicated for me...
Thanks for further help
Michael
 
Reply With Quote
 
Robert Fendt
Guest
Posts: n/a
 
      03-19-2010
And thus spake Mike <(E-Mail Removed)>
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
 
Reply With Quote
 
red floyd
Guest
Posts: n/a
 
      03-19-2010
On Mar 19, 9:47*am, Robert Fendt <(E-Mail Removed)> wrote:
> And thus spake Mike <(E-Mail Removed)>
> 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.
 
Reply With Quote
 
mickCyber
Guest
Posts: n/a
 
      03-20-2010
What do you mean?
> However, as always, FAQ 5.8 applies.


First error here in the code:
VertexTextureIndex *ret = malloc(sizeof(VertexTextureIndex));
 
Reply With Quote
 
Paul N
Guest
Posts: n/a
 
      03-20-2010
On 20 Mar, 07:01, mickCyber <(E-Mail Removed)> 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.
 
Reply With Quote
 
mickCyber
Guest
Posts: n/a
 
      03-21-2010
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(O penGLWaveFrontMaterial::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
 
Reply With Quote
 
Jonathan Lee
Guest
Posts: n/a
 
      03-21-2010
On Mar 21, 11:57*am, mickCyber <(E-Mail Removed)> 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
 
Reply With Quote
 
mickCyber
Guest
Posts: n/a
 
      03-22-2010
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::Vert exTextureIndexMake
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(O penGLWaveFrontMaterial::VertexTextureIndex*,
GLuint,
GLuint)


---
thanks again
Michael
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
invalid character in base-64 string and invalid postback or callba kevin ASP .Net 0 01-16-2008 09:39 PM
How do fix: "Wrong number of arguments" / "invalid propert assignment"/ "Invalid argument" Java Guy Javascript 1 10-15-2006 08:41 PM
How do fix: "Wrong number of arguments" / "invalid propert assignment"/ "Invalid argument" Java Guy Java 1 10-15-2006 08:31 PM
Invalid URI: There is an invalid sequence in the string. Error!! Patrick.O.Ige ASP .Net 1 07-02-2006 11:21 AM
invalid@invalid.org Hank Sniadoch Computer Information 1 08-20-2004 11:24 AM



Advertisments