Anderson Ilha dos Santos
2002-10-14 18:19:05 UTC
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.
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.