invalid conversion & operator
I think I got a quite easy problem. I am learning C++ with the tutorial on your website about pointers.
My problem is when I take the codeexample with andy and fred and put it into a simple environment:
using namespace std;
andy = 25;
fred = andy;
ted = &andy;
cout << 2 << endl;
I got the error mesage :
invalid code conversion from 'int' to '*int'
When I initialize ted as a pointer it works. But why can't I store the adress of andy into an ordinary int variable?
I found the error message at google but in most cases in more complex problems.
I am curious for your answer.
Thanks for your help.
Last edited on
It's just the compiler trying to stop you from making a mistake.
// you can cast your way out of it, although you shouldn't
ted = reinterpret_cast<int> (&andy); // obvious C++ cast
ted = (int)&andy; // evil C cast
ted = int(&andy); // evil alien C++ cast
Please store addresses in pointers, like you're supposed to
Topic archived. No new replies allowed.