Click here to Skip to main content
16,013,747 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Questionhow can i keep my EXE file's integerity? Pin
tiaozi28-May-02 22:46
tiaozi28-May-02 22:46 
AnswerRe: how can i keep my EXE file's integerity? Pin
Mike Nordell28-May-02 22:52
Mike Nordell28-May-02 22:52 
AnswerRe: how can i keep my EXE file's integerity? Pin
Martin Ziacek28-May-02 23:27
Martin Ziacek28-May-02 23:27 
GeneralMS Excel automation Pin
28-May-02 22:53
suss28-May-02 22:53 
GeneralRe: MS Excel automation Pin
KarstenK29-May-02 0:14
mveKarstenK29-May-02 0:14 
QuestionSimple template function question? Pin
28-May-02 22:12
suss28-May-02 22:12 
AnswerRe: Simple template function question? Pin
Mike Nordell28-May-02 23:00
Mike Nordell28-May-02 23:00 
AnswerRe: Simple template function question? Pin
Rutger Ellen28-May-02 23:54
Rutger Ellen28-May-02 23:54 
You should use a template specialization as follows

template <T> void MyFuction(T* Para)
{
...
}

is still the unspecialized
Specialization for MyClassA

template<> void MyFuction(MyClassA* Para)
{
if(sizeof(T) == sizeof(MyClassA))
Para->Method_Of_MyClassA();
...
}
Specialization for class B

template<> void MyFuction(MyClassB* Para)
{
Para->Method_Of_MyClassB();
...
}

It's impossible as you want it to be handled because the compiler will try to evaluate the terms. Also you are using a run time check that is not needed if you use specialization because the compiler will check it for you (that's why you are getting errors, so it's even faster Smile | :)

If you have a lot of code in your function you could also create a helper template function that is specialized to call the proper method_of_myclass. and thus keeping your original function unspecialized (hey you could make a template class of it with some specialized functions and some not specialized)

Good luck
Rutger

Wayne King wrote:
I have define the below template function:

template void MyFuction(T* Para)
{
if(sizeof(T) == sizeof(MyClassA))
Para->Method_Of_MyClassA();
else
Para->Method_Of_MyClassB();
...
}

To use this template class, I will pass pointer of MyClassA and MyClassB
as a parameter to it;
eg.

MyFuction(pMyClassA);
MyFuction(pMyClassB);

But I got compiler error saying Method_Of_MyClassA() not a member MyClassB
and Method_Of_MyClassB() not a member MyClassA.

Does anyone know how to overcome this problem?

Best Regards,
Wayne King

AnswerRe: Simple template function question? Pin
_Magnus_29-May-02 0:14
_Magnus_29-May-02 0:14 
AnswerRe: Simple template function question? Pin
29-May-02 2:32
suss29-May-02 2:32 
GeneralRe: Simple template function question? Pin
Rutger Ellen29-May-02 3:36
Rutger Ellen29-May-02 3:36 
GeneralRe: Simple template function question? Pin
30-May-02 16:12
suss30-May-02 16:12 
GeneralMAKEWPARAM Pin
Arjan Schouten28-May-02 21:41
Arjan Schouten28-May-02 21:41 
GeneralRe: MAKEWPARAM Pin
Arjan Schouten28-May-02 23:23
Arjan Schouten28-May-02 23:23 
GeneralRe: MAKEWPARAM Pin
Mike Nordell28-May-02 23:40
Mike Nordell28-May-02 23:40 
GeneralRe: MAKEWPARAM Pin
Alex Cramer29-May-02 0:01
Alex Cramer29-May-02 0:01 
GeneralRe: MAKEWPARAM Pin
Arjan Schouten29-May-02 0:05
Arjan Schouten29-May-02 0:05 
Generalsize and position of a control like a button or static text. Pin
aldeba28-May-02 21:26
aldeba28-May-02 21:26 
GeneralRe: size and position of a control like a button or static text. Pin
Eugene Pustovoyt28-May-02 21:36
Eugene Pustovoyt28-May-02 21:36 
GeneralRe: size and position of a control like a button or static text. Pin
Mike Nordell28-May-02 21:33
Mike Nordell28-May-02 21:33 
GeneralRe: size and position of a control like a button or static text. Pin
Joaquín M López Muñoz28-May-02 21:42
Joaquín M López Muñoz28-May-02 21:42 
GeneralRe: size and position of a control like a button or static text. Pin
aldeba28-May-02 21:58
aldeba28-May-02 21:58 
GeneralRe: size and position of a control like a button or static text. Pin
Mike Nordell28-May-02 22:51
Mike Nordell28-May-02 22:51 
GeneralRe: size and position of a control like a button or static text. Pin
aldeba30-May-02 0:45
aldeba30-May-02 0:45 
GeneralConverting from CString to std::string Pin
Poul Haahr Klemmensen28-May-02 20:33
Poul Haahr Klemmensen28-May-02 20:33 

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.