using templates as class members.

T

tehn yit chin

Hi all,

I am starting to learn c++ and have come across a problem that I was
not able to get a hang of.

I have a class defintion such as

class vect
{
public:
vect();
~vect();

private

vector<int> my_ints;
}

Upon compling this, my compiler complains vector is used as type, but
is not defined as a type.

I want to do the above because I want to access my_ints in more than
one method in the vect implementation.

I am probably doing something totally stupid. Any help is appreciated.

thanks,
tyc
 
J

Jeff Schwab

tehn said:
Hi all,

I am starting to learn c++ and have come across a problem that I was
not able to get a hang of.

I have a class defintion such as

#include said:
class vect
{
public:
vect();
~vect();

private

vector<int> my_ints;

std::vector<int> my_ints;

/* Vector is in a namespace called std.
* See also the documentation for the "using" keyword.
*/
 
T

Thomas Wintschel

tehn yit chin said:
Hi all,

I am starting to learn c++ and have come across a problem that I was
not able to get a hang of.

I have a class defintion such as

class vect
{
public:
vect();
~vect();

private

vector<int> my_ints;
}

Upon compling this, my compiler complains vector is used as type, but
is not defined as a type.

I want to do the above because I want to access my_ints in more than
one method in the vect implementation.

I am probably doing something totally stupid. Any help is appreciated.

thanks,
tyc

May be a namespace issue. Try:

std::vector<int> my_ints;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top