I'd like to override the operator 'new' for a class and at the same time allow myself the ability to create an object on the stack. Can't do it nohow with gcc 4.5.3 and am wondering if it is possible to do it at all. I realize that there is ambiguity in the expression 'classType name()' where 'name()' was to be a reference to the constructor. Is there anyway around this?
Not sure I follow, using your override new you allocate heap. Creating your class object without using new, allocates it on the stack. Is your main with base b1(); not working?
You are correct. 'base b1()'; does not work. The error message is "error: request for member ‘output’ in ‘b1’, which is of non-class type ‘base()’" One solution may be to include an argument and see if that works - other forums indicate that the error is due to the compiler thinking the declaration is for a function named 'b1()' returning an object of type 'base'. I'm going to try this now.
When using a default constructor with no parameters, it's not required to have the parentheses. If you do use the parentheses, the compiler will interpret it as a function, hence the statement of requesting a member from a non-class type.
First of all, as NGen said, deafault constructors are, as thir name suggests, DEFAULT! That means tehey are implicitly called every time a class object is constructed without any other constructor BY DEFAULT. Second of all, the operator new is used to put objects on the HEAP, not the STACK! The call stack is the default place to put objects on! Better read the tutorial ( http://www.cplusplus.com/doc/tutorial/ )! There they explain both default constructors, and which operators are overloadable, and which are not!