Code samples Code: class A { : void setter( char c); char getter(); }; class B{ public: A& operator() (int x){ A newA; return newA; }; }; Is this a not so good approach? Is newA being created immediately or only during the time operator() is used? thanks!
This is not good approach for some other reason like you are returning the address of a variable which is out of scope. Now about your query newA is created when the operator function is called.
will this approach be better? Code: class B{ private: A newA; public: A& operator() (int x){ return newA; }; }; so this means, whenever B is instantiated, newA will be created. am i right?