Thread: Re: [Dev-C++] static vector initialization
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Daniel G. <sp...@ho...> - 2002-10-16 11:06:28
|
I am sure that the only way to initialise static members si with a static
member function, but I don't know about vectors.
Is static const int size = 10; actually allowed?
>From: Anderson Ilha dos Santos <ai...@if...>
>To: dev...@li...
>Subject: [Dev-C++] static vector initialization
>Date: Mon, 14 Oct 2002 18:10:36 -0200
>
>
>Greetings,
>
>I have been working on a set of utility functions that I gruped together on
>an
>entirely static class. The
>private part of this class has a (static) STL vector container whose
>components
>I have had trouble to
>intialize. My class partial listing can be given as below,
>
>// file utility.hpp
>class Utility
>{
> // public interface ...
>
> private:
> static const int size = 10;
> static vector<double> vec;
>}
>
>// file utility.cpp
>#include "Utility.hpp"
>const int Utility::size;
>vector<double> Utility::vec( size );
>
>the private member 'size' can be directly initialized in the class body
>because
>it is a static
>integral value. However, I was unable to intialize the vec components
>(vec[0],
>vec[1], etc.) directly
>below the vector<double> vec declaration in the utility.cpp file, just as I
>would have for the other
>static private members of the class. The only way I have found to
>initiliaze
>the vec components was
>to use a new function, say 'void init_vec()', and then initialize the
>components inside this new function.
>
>I would like to know whether this is indeed the case or if I am missing
>something. The init_vec()
>approach seems to be something like a "makeshift" constructor, and I would
>prefer to be able to
>initialize the container components just as I would have to a usual static
>member.
>
>I will appreciate any advice you guys can give me.
>
> Regards, Anderson.
>
>
>
>
>-------------------------------------------------------
>This sf.net email is sponsored by:ThinkGeek
>Welcome to geek heaven.
>http://thinkgeek.com/sf
>_______________________________________________
>Dev-cpp-users mailing list
>Dev...@li...
>TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
>https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
_________________________________________________________________
Broadband? Dial-up? Get reliable MSN Internet Access.
http://resourcecenter.msn.com/access/plans/default.asp
|
|
From: Per W. <pw...@ia...> - 2002-10-16 11:18:47
|
Depends on compiler version. If you need backwards compatibility, it
shouldn't be used.
/Per W
On Wed, 16 Oct 2002, Daniel Glenfield wrote:
> I am sure that the only way to initialise static members si with a static=
=20
> member function, but I don't know about vectors.
>=20
> Is static const int size =3D 10; actually allowed?
>=20
>=20
>=20
>=20
>=20
>=20
> >From: Anderson Ilha dos Santos <ai...@if...>
> >To: dev...@li...
> >Subject: [Dev-C++] static vector initialization
> >Date: Mon, 14 Oct 2002 18:10:36 -0200
> >
> >
> >Greetings,
> >
> >I have been working on a set of utility functions that I gruped together=
on=20
> >an
> >entirely static class. The
> >private part of this class has a (static) STL vector container whose=20
> >components
> >I have had trouble to
> >intialize. My class partial listing can be given as below,
> >
> >// file utility.hpp
> >class Utility
> >{
> > // public interface ...
> >
> > private:
> > static const int size =3D 10;
> > static vector<double> vec;
> >}
> >
> >// file utility.cpp
> >#include "Utility.hpp"
> >const int Utility::size;
> >vector<double> Utility::vec( size );
> >
> >the private member 'size' can be directly initialized in the class body=
=20
> >because
> >it is a static
> >integral value. However, I was unable to intialize the vec components=20
> >(vec[0],
> >vec[1], etc.) directly
> >below the vector<double> vec declaration in the utility.cpp file, just a=
s I
> >would have for the other
> >static private members of the class. The only way I have found to=20
> >initiliaze
> >the vec components was
> >to use a new function, say 'void init_vec()', and then initialize the
> >components inside this new function.
> >
> >I would like to know whether this is indeed the case or if I am missing
> >something. The init_vec()
> >approach seems to be something like a "makeshift" constructor, and I wou=
ld
> >prefer to be able to
> >initialize the container components just as I would have to a usual stat=
ic
> >member.
> >
> >I will appreciate any advice you guys can give me.
> >
> > Regards, Anderson.
> >
> >
> >
> >
> >-------------------------------------------------------
> >This sf.net email is sponsored by:ThinkGeek
> >Welcome to geek heaven.
> >http://thinkgeek.com/sf
> >_______________________________________________
> >Dev-cpp-users mailing list
> >Dev...@li...
> >TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
> >https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>=20
>=20
> _________________________________________________________________
> Broadband?=A0Dial-up? Get reliable MSN Internet Access.=20
> http://resourcecenter.msn.com/access/plans/default.asp
>=20
>=20
>=20
> -------------------------------------------------------
> This sf.net email is sponsored by: viaVerio will pay you up to
> $1,000 for every account that you consolidate with us.
> http://ad.doubleclick.net/clk;4749864;7604308;v?
> http://www.viaverio.com/consolidator/osdn.cfm
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>=20
|
|
From: Ioannis V. <no...@ho...> - 2002-10-16 16:33:55
|
> -----Original Message----- > From: dev...@li...=20 > [mailto:dev...@li...] On Behalf=20 > Of Daniel Glenfield > Sent: Wednesday, October 16, 2002 2:06 PM > To: ai...@if...; dev...@li... > Subject: Re: [Dev-C++] static vector initialization >=20 >=20 > I am sure that the only way to initialise static members si=20 > with a static=20 > member function, but I don't know about vectors. >=20 > Is static const int size =3D 10; actually allowed? A static member is a regular global namespace entity (object or function) which for notational purposes is defined inside the class definition (and the function as a member function style while it is not). For static integral members the initialization can be done inside the class declaration without needing an external definition as with other types. This is only supported by recent compiler releases (compiler vendors had more important ANSI C++ things to implement than that in the past). Ioannis * Ioannis Vranos * Programming pages: http://www.noicys.freeurl.com * Alternative URL: http://run.to/noicys |