Click here to Skip to main content
15,912,897 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Generaloverloading operator() in c++ Pin
Kri519-Jan-04 22:08
Kri519-Jan-04 22:08 
GeneralRe: overloading operator() in c++ Pin
Abhishek Srivastava19-Jan-04 22:27
Abhishek Srivastava19-Jan-04 22:27 
GeneralRe: overloading operator() in c++ Pin
Kri519-Jan-04 22:35
Kri519-Jan-04 22:35 
GeneralRe: overloading operator() in c++ Pin
Taka Muraoka19-Jan-04 22:44
Taka Muraoka19-Jan-04 22:44 
GeneralRe: overloading operator() in c++ Pin
Kri519-Jan-04 22:52
Kri519-Jan-04 22:52 
GeneralRe: overloading operator() in c++ Pin
Abhishek Srivastava19-Jan-04 22:44
Abhishek Srivastava19-Jan-04 22:44 
GeneralRe: overloading operator() in c++ Pin
Kri519-Jan-04 22:50
Kri519-Jan-04 22:50 
GeneralRe: overloading operator() in c++ Pin
Maxwell Chen19-Jan-04 22:52
Maxwell Chen19-Jan-04 22:52 
Christopher Spiteri wrote:
class A
{
 public:
  int value;
  // ...
  operator int()
  {
     return value;
  }
  // ...
};

Since there's only one value type operator, int, in your class A, cout will take it implicitly.

So you can write it like this:
cout << "value:" << a1 << endl;

And, operator int() is for something like this:
cout << "value:" << (int)a1 << endl;


Overloading () would be this way:
A& operator ()()
 {
  cout << "In operator ()\n";
  return *this;
 }
Therefore, in main, you can write this:
int main()
{
	A a1(27);
	++a1; // this works fine...
	
	a1(); // This line.
	return 0;
}


Maxwell Chen
GeneralRe: overloading operator() in c++ Pin
Kri519-Jan-04 23:53
Kri519-Jan-04 23:53 
QuestionHow to remove silence from Wave file...? Pin
Srinivasa Rao Madala19-Jan-04 22:05
Srinivasa Rao Madala19-Jan-04 22:05 
QuestionHow to create a sizeable dialog (under MFC)? Pin
Jay.Jay19-Jan-04 21:57
Jay.Jay19-Jan-04 21:57 
AnswerRe: How to create a sizeable dialog (under MFC)? Pin
Brian D19-Jan-04 22:00
Brian D19-Jan-04 22:00 
AnswerRe: How to create a sizeable dialog (under MFC)? Pin
Burz20-Jan-04 0:49
Burz20-Jan-04 0:49 
GeneralRe: How to create a sizeable dialog (under MFC)? Pin
Jay.Jay22-Jan-04 3:11
Jay.Jay22-Jan-04 3:11 
GeneralRe: How to create a sizeable dialog (under MFC)? Pin
Burz22-Jan-04 3:33
Burz22-Jan-04 3:33 
GeneralRe: How to create a sizeable dialog (under MFC)? Pin
Jay.Jay22-Jan-04 23:58
Jay.Jay22-Jan-04 23:58 
QuestionDifferent behaviour between CommonControl- and MSForm- Buttons ?? Pin
Mephisto18719-Jan-04 21:42
Mephisto18719-Jan-04 21:42 
GeneralCant compile GetComputerNameEx Pin
bjolletts19-Jan-04 21:39
bjolletts19-Jan-04 21:39 
GeneralRe: Cant compile GetComputerNameEx Pin
Steve S19-Jan-04 22:22
Steve S19-Jan-04 22:22 
QuestionHow to get &quot;password policy requirement&quot;? Pin
Aleksan19-Jan-04 21:32
Aleksan19-Jan-04 21:32 
QuestionHow to find the exe programmatically Pin
SiddharthAtw19-Jan-04 20:14
SiddharthAtw19-Jan-04 20:14 
AnswerRe: How to find the exe programmatically Pin
murali_utr19-Jan-04 20:22
murali_utr19-Jan-04 20:22 
GeneralScreen Capturing and saving in .AVI Pin
santosh k19-Jan-04 20:12
santosh k19-Jan-04 20:12 
GeneralRe: Screen Capturing and saving in .AVI Pin
Abhishek Srivastava19-Jan-04 22:39
Abhishek Srivastava19-Jan-04 22:39 
GeneralRe: Screen Capturing and saving in .AVI Pin
Thierry Maurel19-Jan-04 22:53
Thierry Maurel19-Jan-04 22:53 

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.