General Question

HeroicZach's avatar

Is it possible in C++ to declare a vector of characters as a private variable in a class header file? If so, why isn't it working for me?

Asked by HeroicZach (195points) September 19th, 2009

When I declare, like this:

class myClass
{
public:
//public functions
private:
vector<char> myVector;
}

The program compiles, but when I set up the default constuctor in the .cpp file that matches up with this .h class header, like this:

myClass::myClass()
{
myVector(‘a’,‘b’,‘c’);
}

…the program does not compile. What’s the deal?

Observing members: 0 Composing members: 0

3 Answers

oratio's avatar

Just throwing this in. Have you cleaned, before you execute?

ratboy's avatar

You are not using the correct syntax for the vector constructor. Look at the specification at Dinkumware.

Babbage's avatar

If you want to put an entire array in to the vector at once, I suggest you check out this page (specifically the last example): http://www.cppreference.com/wiki/stl/vector/vector_constructors

If you don’t want to use arrays, then I suggest using the push_back function. Examples of this can be found here: http://www.cppreference.com/wiki/stl/vector/push_back

Answer this question

Login

or

Join

to answer.

This question is in the General Section. Responses must be helpful and on-topic.

Your answer will be saved while you login or join.

Have a question? Ask Fluther!

What do you know more about?
or
Knowledge Networking @ Fluther