I have
what did I do wrong?Code:
void* classname::data(){ //this function works fine
return data;
}
classname::operator char*(){ //this one cause the program to crash
return (char*)(data());
}
Printable View
I have
what did I do wrong?Code:
void* classname::data(){ //this function works fine
return data;
}
classname::operator char*(){ //this one cause the program to crash
return (char*)(data());
}
Impossible to tell without more code.
Show the simplest possible compilable example that reproduces the problem.
what's the type of data?
data is void* type
How are you setting data, and how are you using classname in a char* context? One way or another the two don't work together.
In general you should avoid void * and C casts because they undermine the type system.
this is what I have to do
create :
operator char*();
Overload the char* cast to return the value of _Label.data()
_Label.data() return a void* type.
so what I did was
Code:classname::operator char*(){ //this one cause the program to crash
return (char*)(_Label.data());
}
That's great, but that doesn't set the value of data, or use the resultant char *.
I think my syntax is correct.
The problem probably lie on what actually inside data ><.
Your program compiled, so it is possible that the syntax is correct. A correct program has correct syntax, but not all programs with correct syntax are correct. So...Quote:
Originally Posted by byebyebyezzz
Quote:
Originally Posted by Elysia
I fixed the porblem. (the problem was with my team member's code)
It's working fine now.
Thanks all