Click here to Skip to main content
15,885,198 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: [Challenge/Puzzle] Implement reinterpret_cast Pin
Matthew Faithfull13-Mar-13 11:18
Matthew Faithfull13-Mar-13 11:18 
GeneralRe: [Challenge/Puzzle] Implement reinterpret_cast Pin
MicroVirus13-Mar-13 11:29
MicroVirus13-Mar-13 11:29 
GeneralRe: [Challenge/Puzzle] Implement reinterpret_cast Pin
Stefan_Lang11-Mar-13 3:29
Stefan_Lang11-Mar-13 3:29 
GeneralRe: [Challenge/Puzzle] Implement reinterpret_cast Pin
harold aptroot11-Mar-13 9:03
harold aptroot11-Mar-13 9:03 
GeneralRe: [Challenge/Puzzle] Implement reinterpret_cast Pin
Stefan_Lang11-Mar-13 22:30
Stefan_Lang11-Mar-13 22:30 
GeneralRe: [Challenge/Puzzle] Implement reinterpret_cast Pin
Stefan_Lang12-Mar-13 0:09
Stefan_Lang12-Mar-13 0:09 
GeneralRe: [Challenge/Puzzle] Implement reinterpret_cast Pin
MicroVirus13-Mar-13 11:19
MicroVirus13-Mar-13 11:19 
GeneralRe: [Challenge/Puzzle] Implement reinterpret_cast Pin
Stefan_Lang13-Mar-13 23:07
Stefan_Lang13-Mar-13 23:07 
Originally my idea was to use a struct of function pointers and 'iterate' over them to arrive at a different pointer. However, I found that pointer arithmetic apparently doesn't work on function pointers. Frown | :( That is when I thought of union. It was only later that I realized the union construct can solve the task by itself. But since I already posted my solution, there was no point in 'watering it down'. Wink | ;)

Another thing I thought of is overloading virtual functions with different return types. But it would require at least a downcast of the instance pointer:
C++
class base {
public:
   virtual ~base() {}
   virtual int* foo(int i) { return &i; }
};
class derived : public base {
public:
   virtual ~derived() {}
   virtual int foo(int i) { return i; } // overrides base::foo()
};
int* bar(int i) {
   base* caster = new derived; // implicit downcast here
   int* pi = caster->foo(i); // this is the actual 'reinterpret cast'
   delete caster;
   return pi:
}

I wonder if I could get this to work if I put part of the code inside a constructor, before the construction of the vtable - but then the behaviour would be undefined D'Oh! | :doh:
Questiontinyxml Pin
venkatesh528678-Mar-13 16:43
venkatesh528678-Mar-13 16:43 
AnswerRe: tinyxml Pin
Richard MacCutchan8-Mar-13 21:48
mveRichard MacCutchan8-Mar-13 21:48 
AnswerRe: tinyxml Pin
Albert Holguin10-Mar-13 14:39
professionalAlbert Holguin10-Mar-13 14:39 
QuestionInsert is working but Select from this music site is not! Pin
Ericdick8-Mar-13 1:48
Ericdick8-Mar-13 1:48 
GeneralRe: Insert is working but Select from this music site is not! Pin
Jochen Arndt8-Mar-13 1:54
professionalJochen Arndt8-Mar-13 1:54 
QuestionHow can i put Install button in my mfc property sheet Pin
venkatesh528677-Mar-13 3:28
venkatesh528677-Mar-13 3:28 
AnswerRe: How can i put Install button in my mfc property sheet Pin
Richard MacCutchan7-Mar-13 3:34
mveRichard MacCutchan7-Mar-13 3:34 
QuestionRe: How can i put Install button in my mfc property sheet Pin
David Crow7-Mar-13 7:47
David Crow7-Mar-13 7:47 
QuestionJSON Parser Pin
john56326-Mar-13 23:20
john56326-Mar-13 23:20 
AnswerRe: JSON Parser Pin
CPallini7-Mar-13 0:17
mveCPallini7-Mar-13 0:17 
QuestionRe: JSON Parser Pin
David Crow7-Mar-13 3:00
David Crow7-Mar-13 3:00 
Questionrsa decryption using gmp Pin
etesi6-Mar-13 14:51
etesi6-Mar-13 14:51 
AnswerRe: rsa decryption using gmp Pin
Richard MacCutchan6-Mar-13 22:26
mveRichard MacCutchan6-Mar-13 22:26 
GeneralRe: rsa decryption using gmp Pin
parths7-Mar-13 22:38
parths7-Mar-13 22:38 
AnswerRe: rsa decryption using gmp Pin
parths7-Mar-13 22:42
parths7-Mar-13 22:42 
AnswerRe: rsa decryption using gmp Pin
Stefan_Lang11-Mar-13 3:23
Stefan_Lang11-Mar-13 3:23 
QuestionOpen A File Just Like MS Word Does Pin
dliviu6-Mar-13 2:20
dliviu6-Mar-13 2:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.