TITLE: precedence and order of operations (Newsgroups: comp.std.c++, 4 Mar 99) GROB: "Daniel Grob" > If I write the following line of code: > > IC_String *test = new IC_String(IC_String::fkt()) > > where > IC_String is a class > new is the overloaded operator for the IC_String class > fkt() is a simple function returning an long > IC_String(long) is a contstructor for the IC_String class > > In what sequence are the functions / operators called? > > In my C++ book I see, that a constructor has precedence over the new > operator. So the sequence should be: > > 1. the function IC_String::fkt() > 2. the constructor IC_String() > 3. the new operator CLAMAGE: Steve Clamage You are confusing precedence with order of operations. Precedence determines only how operations are grouped. It establishes a partial ordering, not necessarily a total ordering. Example: f() + g() / h() Since / has higher precedence than +, the result of the division must be known before the addition can be performed. But the three functions can be called in any order. The only other requirements are that g and h must be called before the division can be performed, and f must be called before the addition can be performed. Any ordering that meets those requirements is acceptable. In your example, you can't invoke the the constructor until its argument has been evaluated, so fkt must be called before the constructor. The constructor can be invoked only if memory has been allocated for it to operate on. That means that operator new must be called before the constructor can be called. The assignment of a value to "test" can occur only after operator new has returned a value. So we have this partial ordering: operator new before the constructor fkt before the constructor operator new before the assignment to test Any ordering that satisfies those requirements is acceptable.