[Discuss] SemiOT - Question for the C++ gurus
pw
p.willis at telus.net
Sun Mar 4 07:17:52 PST 2007
Adam Parkin wrote:
> Okay I realize this isn't a C++ list, but I know there are a few C++
> gurus on the list.
>
> How does one indicate in a constructor a default initialization for a
> std::vector object? Like what I want is in my default constructor for
> my class (which takes a vector as an argument) to initialize a private
> member vector to be empty if one isn't supplied to the constructor. Or
> in code:
>
> class SomeClass
> {
> public:
> // what goes in the ????? spot?
> SomeClass (std::vector<string> vecIn = ?????) : privVec (vecIn);
> private:
> std::vector<std::string> privVec;
> };
>
> SomeClass Foo (); // Foo.privVec initialized with empty vector
> SomeClass Bar (someVector); // Bar.privVec initialized with someVector
>
> I'm just not sure what to put in the ????? spot in the constructor above.
>
> Thanks in advance....
Is this your homework............?
class SomeClass
{
public:
///should set this to a default array value
static std::vector<std::string> m_vec;
myvec(std::vector<std::string> vecIn = m_vec):privVec(vecIn){
///yada
}
private:
std::vector<std::string> privVec;
};
Peter
More information about the Discuss
mailing list