Skip to main content
GameDev.net gamedev.net
🔒 Locked

[c++] overloading operator ()

Started by sipickles Jul 4, 2008 at 8:07 AM 1 replies 850+ views
Original Post
sipickles
sipickles
Hi, Can anyone tell me if it is possible to overload the call method ()? Heres what I tried: class MyDXDevice { public: IDirect3DDevice9* operator()(void) { return m_device; } private: IDirect3DDevice9* m_device; }; but using MyDXDevice() causes: error C2064: term does not evaluate to a function taking 0 arguments Thanks all! Simon
ToohrVyk
ToohrVyk
You need to create an instance.

MyDXDevice device;device();
Hnefi
Hnefi
Calling MyDXDevice() calls the constructor, not operator(). See example:
#include <iostream>using namespace std;class test{public:  int operator()() {return 5;};};int main(){  test t;  cout << t() << endl; //works fine. Outputs 5.  cout << test() << endl; //ERROR! Attempting to call the constructor, which does not return a type for which operator<< is defined.}
-------------Please rate this post if it was useful.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.