Click here to Skip to main content
15,894,539 members
Home / Discussions / C#
   

C#

 
GeneralRe: Referencing a reference Pin
Furty5-Aug-03 14:10
Furty5-Aug-03 14:10 
GeneralRe: Referencing a reference Pin
Heath Stewart4-Aug-03 6:11
protectorHeath Stewart4-Aug-03 6:11 
GeneralRe: Referencing a reference Pin
Martin Cross4-Aug-03 6:24
Martin Cross4-Aug-03 6:24 
GeneralRe: Referencing a reference Pin
Heath Stewart4-Aug-03 6:34
protectorHeath Stewart4-Aug-03 6:34 
QuestionHow to get system-wide cursor status in c#? Pin
CyberKewl3-Aug-03 22:02
CyberKewl3-Aug-03 22:02 
AnswerRe: How to get system-wide cursor status in c#? Pin
J. Dunlap3-Aug-03 22:34
J. Dunlap3-Aug-03 22:34 
GeneralRe: How to get system-wide cursor status in c#? Pin
CyberKewl4-Aug-03 4:25
CyberKewl4-Aug-03 4:25 
GeneralAbout some syntax Pin
FlyingDancer3-Aug-03 21:40
FlyingDancer3-Aug-03 21:40 
//----------------------------------------------------------------------------
// 4.2 How to Implement Functors

// 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;
}


Can you tell me the underlined sentences' meaning?
Thank you!
GeneralRe: About some syntax Pin
Alexander Kojevnikov3-Aug-03 22:41
Alexander Kojevnikov3-Aug-03 22:41 
GeneralRe: About some syntax Pin
FlyingDancer3-Aug-03 23:03
FlyingDancer3-Aug-03 23:03 
GeneralRe: About some syntax Pin
Alexander Kojevnikov4-Aug-03 2:42
Alexander Kojevnikov4-Aug-03 2:42 
GeneralRe: About some syntax Pin
FlyingDancer4-Aug-03 2:55
FlyingDancer4-Aug-03 2:55 
GeneralReturn possibilty Pin
deanoA3-Aug-03 16:33
deanoA3-Aug-03 16:33 
GeneralRe: Return possibilty Pin
James T. Johnson3-Aug-03 16:59
James T. Johnson3-Aug-03 16:59 
GeneralRe: Return possibilty Pin
Furty3-Aug-03 17:04
Furty3-Aug-03 17:04 
GeneralRe: Return possibilty Pin
James T. Johnson3-Aug-03 17:10
James T. Johnson3-Aug-03 17:10 
GeneralRe: Return possibilty Pin
Furty3-Aug-03 17:24
Furty3-Aug-03 17:24 
GeneralRe: Return possibilty Pin
Furty3-Aug-03 17:00
Furty3-Aug-03 17:00 
GeneralRe: Return possibilty Pin
James T. Johnson3-Aug-03 17:03
James T. Johnson3-Aug-03 17:03 
GeneralRe: Return possibilty Pin
Furty3-Aug-03 17:09
Furty3-Aug-03 17:09 
GeneralRe: Return possibilty Pin
deanoA3-Aug-03 17:03
deanoA3-Aug-03 17:03 
Generalprinting Pin
karan_sandhu3-Aug-03 13:49
karan_sandhu3-Aug-03 13:49 
GeneralRe: printing Pin
James T. Johnson3-Aug-03 17:42
James T. Johnson3-Aug-03 17:42 
GeneralCLR error Pin
karan_sandhu3-Aug-03 13:44
karan_sandhu3-Aug-03 13:44 
GeneralRe: CLR error Pin
Alex Korchemniy3-Aug-03 18:47
Alex Korchemniy3-Aug-03 18:47 

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.