Topic: Objects with no default constructor in vectors<>
Author: Oleg Zabluda <zabluda@math.psu.edu>
Date: 1998/03/06 Raw View
Olle Bjurstam <olle.bjurstam@senet.abb.se> wrote:
: I'm currently using VC++ 5.0 and it refuses to compile since
: there is no default constructor for my class.
: explicit vector( size_type _N,
: const _Ty& _V = _Ty(), <<== here it barks
: const _A& _Al = _A() )
: I do think I recall that the article said that the compiler
: shouldn't try to use the default argument value here since
: I supply my own, as in:
: vector<X> a( 100 ); // shouldn't work, no default ctor
: vector<X> b( 100, X( 1 ) ); // should be ok, default
: // ctor not needed
: Am I right?
Yes.
Oleg.
--
Life is a sexually transmitted, 100% lethal disease.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Olle Bjurstam <olle.bjurstam@senet.abb.se>
Date: 1998/03/04 Raw View
Sorry if this has been discussed earlier. If so, please give me
a hint of where I can catch up.
I think I recall that I read somewhere that you should be able
to construct standard library vectors for objects without
default constructors. It seems resonable since there is a
constructor in vector<> that takes an object with which to fill
the vector.
I'm currently using VC++ 5.0 and it refuses to compile since
there is no default constructor for my class.
explicit vector( size_type _N,
const _Ty& _V = _Ty(), <<== here it barks
const _A& _Al = _A() )
I do think I recall that the article said that the compiler
shouldn't try to use the default argument value here since
I supply my own, as in:
vector<X> a( 100 ); // shouldn't work, no default ctor
vector<X> b( 100, X( 1 ) ); // should be ok, default
// ctor not needed
Am I right?
,,,
--------------ooO-(. .)-Ooo--------------------------------------
Olle Bjurstam (_) | Email: olle.bjurstam@senet.abb.se
Dept. TA | Phone: +46 21 324147
ABB Network Partner AB | Fax : +46 21 188291
S-721 71 VASTERAS, SWEDEN | Telex: 40849 ABBNET S
"You can make it foolproof, but you can't make it damnfoolproof."
-----------------------------------------------------------------
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]