Click here to Skip to main content
15,906,708 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Generalwindows help-topic does not exit error Pin
haritadala4-Aug-03 0:04
haritadala4-Aug-03 0:04 
GeneralRe: windows help-topic does not exit error Pin
HPSI4-Aug-03 0:25
HPSI4-Aug-03 0:25 
GeneralRe: windows help-topic does not exit error Pin
haritadala4-Aug-03 0:57
haritadala4-Aug-03 0:57 
GeneralProgram too big to fit in memory Pin
JensB3-Aug-03 23:37
JensB3-Aug-03 23:37 
GeneralCtreeCtrl Tool Tips Pin
Marissa1823-Aug-03 23:36
Marissa1823-Aug-03 23:36 
GeneralRe: CtreeCtrl Tool Tips Pin
Anonymous3-Aug-03 23:52
Anonymous3-Aug-03 23:52 
GeneralRe: CtreeCtrl Tool Tips Pin
HPSI4-Aug-03 0:20
HPSI4-Aug-03 0:20 
GeneralHere are some syntax Pin
FlyingDancer3-Aug-03 22:47
FlyingDancer3-Aug-03 22:47 
Now I meet several problems
1.virtual void operator()(const char* string)=0; // call using operator
2.template <class TClass> class TSpecificFunctor : public TFunctor
//TFunctor is a class
3.TSpecificFunctor<TClassA> specFuncA(&objA, TClassA::Display);
4.TFunctor** vTable = new TFunctor*[2];
5.delete[] vTable;
6.(*vTable[1]) ("TClassB::Display called!"); // via operator "()"
//Why is Table[1]" put into the bracket?

Can you tell me their meaning?
Thank you in advance!



The following codes you can refer:
// This code was compiled and tested with Borland C++ Builder 5.0. Let me know
// if there is something I should mention for the use with other compilers.
#pragma hdrstop // Borland C++ Builder specific
#pragma argsused // do.
#include <iostream.h> // due to: cout
// abstract base class
class TFunctor
{
public:

// two possible functions to call member function. virtual cause derived
// classes will use a pointer to an object and a pointer to a member function
// to make the function call
virtual void operator()(const char* string)=0; // call using operator
virtual void Call(const char* string)=0; // call using function
};


// derived template class
template <class TClass> class TSpecificFunctor : public TFunctor
{
private:
void (TClass::*fpt)(const char*); // pointer to member function
TClass* pt2Object; // pointer to object

public:

// constructor - takes pointer to an object and pointer to a member and stores
// them in two private variables
TSpecificFunctor(TClass* _pt2Object, void(TClass::*_fpt)(const char*))
{ pt2Object = _pt2Object; fpt=_fpt; };

// override operator "()"
virtual void operator()(const char* string)
{ (*pt2Object.*fpt)(string);}; // execute member function

// override function "Call"
virtual void Call(const char* string)
{ (*pt2Object.*fpt)(string);}; // execute member function
};




//-----------------------------------------------------------------------------------------
// 4.3 Example of How to Use Functors

// dummy class A
class TClassA{
public:

TClassA(){};
void Display(const char* text) { cout << text << endl; };

/* more of TClassA */
};

// dummy class B
class TClassB{
public:

TClassB(){};
void Display(const char* text) { cout << text << endl; };

/* more of TClassB */
};


// main program
int main(int argc, char* argv[])
{
// 1. instantiate objects of TClassA and TClassB
TClassA objA;
TClassB objB;


// 2. instantiate TSpecificFunctor objects ...
// a ) functor which encapsulates pointer to object and to member of TClassA
TSpecificFunctor<TClassA> specFuncA(&objA, TClassA::Display);

// b) functor which encapsulates pointer to object and to member of TClassB
TSpecificFunctor<TClassB> specFuncB(&objB, &TClassB::Display);


// 3. create array with pointers to TFunctor, the base class and ...
TFunctor** vTable = new TFunctor*[2];

// ... assign functor addresses to the function pointer array
vTable[0] = &specFuncA;
vTable[1] = &specFuncB;


// 4. use array to call member functions without the need of an object
vTable[0]->Call("TClassA::Display called!"); // via function "Call"
(*vTable[1]) ("TClassB::Display called!"); // via operator "()"


// 5. release
delete[] vTable;


// hit enter to terminate
cout << endl << "Hit Enter to terminate!" << endl;
cin.get();

return 0;
}


GeneralRe: Here are some syntax Pin
Ryan Binns4-Aug-03 1:24
Ryan Binns4-Aug-03 1:24 
GeneralRe: Here are some syntax Pin
FlyingDancer4-Aug-03 1:53
FlyingDancer4-Aug-03 1:53 
GeneralRe: Here are some syntax Pin
Ryan Binns4-Aug-03 1:58
Ryan Binns4-Aug-03 1:58 
GeneralNet*Enum APIs, can't link FileEnum user to host Pin
Fahr3-Aug-03 22:43
Fahr3-Aug-03 22:43 
QuestionHow to play a .mod or .xm music? Pin
lenghost3-Aug-03 22:36
lenghost3-Aug-03 22:36 
AnswerRe: How to play a .mod or .xm music? Pin
Kochise3-Aug-03 23:16
Kochise3-Aug-03 23:16 
GeneralRe: How to play a .mod or .xm music? Pin
lenghost4-Aug-03 15:17
lenghost4-Aug-03 15:17 
QuestionHow to disable displaying &quot;...&quot; in column header when text is wider? Pin
s_k3-Aug-03 22:30
s_k3-Aug-03 22:30 
AnswerRe: How to disable displaying &quot;...&quot; in column header when text is wider? Pin
Kochise4-Aug-03 1:58
Kochise4-Aug-03 1:58 
GeneralOne time initialization after modal dialog box is shown Pin
harmendejong3-Aug-03 21:52
harmendejong3-Aug-03 21:52 
GeneralRe: One time initialization after modal dialog box is shown Pin
David Crow4-Aug-03 5:34
David Crow4-Aug-03 5:34 
GeneralRe: One time initialization after modal dialog box is shown Pin
PJ Arends4-Aug-03 5:42
professionalPJ Arends4-Aug-03 5:42 
QuestionHow to combine a dll into exe-file ? Pin
suninwater3-Aug-03 21:45
suninwater3-Aug-03 21:45 
AnswerRe: How to combine a dll into exe-file ? Pin
Joe Woodbury3-Aug-03 22:05
professionalJoe Woodbury3-Aug-03 22:05 
QuestionHow i can recognize what stream use any control Pin
El'Cachubrey3-Aug-03 21:33
El'Cachubrey3-Aug-03 21:33 
GeneralSerializing class derived from CArray Pin
Mike Ellertson3-Aug-03 20:46
sussMike Ellertson3-Aug-03 20:46 
GeneralRe: Serializing class derived from CArray Pin
Ryan Binns4-Aug-03 2:07
Ryan Binns4-Aug-03 2:07 

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.