Using void pointers

Started by
19 comments, last by Nacho 21 years, 8 months ago
quote:Original post by Coward
Ok, thanks, I feared using void pointers too would give me an Access Violation...

Anyway, would you care to show me how the template soloution would look like?

EDIT: I''m abit offtopic here, right?



  class FirstClass{    bool boolvalue;    int someValue;}class secondclass{    bool boolvalue;    float someValue;}template <typename T, class G>void SomeFunction( T tInput, G gInput){    if(gInput.boolvalue == true)    {        gInput.someValue += tInput;    }}  


Something like that. This is off the top of my head, but you would be able to pass any type T and any class to the function. The function assumes that any class passed to it has boolValue and someValue. I would really look up articles on the web to find out about templates and when you are comfortable with templates, learn STL.

*Before anyone flames me, This is off the top of my head. I did not test this code AT ALL*
quote:
Prince Wang''s programmer was coding software. His fingers danced upon the
keyboard. The program compiled without an error message and ran like a
gentle wind.

"Excellent!" the Prince exclaimed. "Your technique is faultless!"

"Technique?" said the programmer, turning from his terminal, "What I follow
is Tao -- beyond all techniques! When I first began to program, I would see
before me the whole problem in one mass. After three years, I no longer saw
this mass. Instead, I used subroutines. But now I see nothing. My whole
being exists in a formless void. My senses are idle. My spirit, free to
work without a plan, follows its own instinct. In short, my program writes
itself. True, sometimes there are difficult problems. I see them coming, I
slow down, I watch silently. Then I change a single line of code and the
difficulties vanish like puffs of idle smoke. I then compile the program.
I sit still and let the joy of the work fill my being. I close my eyes for
a moment and then log off."

This topic is closed to new replies.

Advertisement