Re: why can't this be a feature in C++?

From: Janusz Szpilewski (janusz.szpilewski_at_symbian.com)
Date: 09/02/04


Date: Thu, 02 Sep 2004 10:31:57 +0100

Paul wrote:
>
> int main()
> {
> A *p1 = new A[3](5); //all objects have same value
> A *p2 = new A[3]((5),(5,10),(20)); //objects have different values
> return 0;
> }
>
> Is there any reason for not having some thing like this, or just
> because of its complex to implement???
>

Array with elements initialised with a non-default constructor was
considered and probably still is implemented by the gcc compiler but
finally the idea was given up to the concept of fill constructor in the
sequence types in the STL library. Check any STL documentation for
further details.

It is used like:

std::vector<int> v(5,3); // vector of 5 ints filled with the 3 value.
or
std::vector<int>* vp = new std::vector<int> (5,3);

Regards,
Janusz



Relevant Pages

  • Re: End-of-the-week fun
    ... Constructor and destructor names may be surrounded by parenthesis. ... > real compelling reason, ... > using namespace std; ... > int main ...
    (comp.lang.cpp)
  • Re: Explicitly calling the constructor
    ... The necessity was to place the scope operator in front of the constructor ... For some reason, this does not work ... > class CTestClass ... > int main ...
    (microsoft.public.vc.language)
  • Re: can I call from one constructor another constructor ?
    ... You can, however, invoke inherited contructors in the constructor signature ... "Paul" wrote in message ... public A (int a, int b, int c) ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: can I call from one constructor another constructor ?
    ... You can, however, invoke inherited contructors in the constructor signature ... "Paul" wrote in message ... public A (int a, int b, int c) ...
    (microsoft.public.dotnet.framework)
  • Re: Initialization: = or () ?
    ... Is either form preferable for some reason I don't ... When you have a class that has a constructor, copy constructor, all sorts of ... SuperClass(unsigned int); ... Are you not then calling the: ...
    (comp.lang.cpp)

Loading