This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Constructor for new T[..]


I found out that it's possible to invoke a non-default constructor when
using 'new' operator to create an array of objects.

class Fred {
   public:
        Fred() { cout << "default" << endl; }
        Fred(int i, int j) { cout << i << ", " << j << endl; }
};

int main()
{
    Fred *f = new Fred[2](2, 5);
}


None of the sources I've seen say that this is legal. Is this a GCC
extension?

-Andrei                                       http://www.gravitonic.com/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]