using templates as class members.

Discussion in 'C++' started by tehn yit chin, Dec 18, 2003.

  1. 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
    tehn yit chin, Dec 18, 2003
    #1
    1. Advertising

  2. tehn yit chin

    Jeff Schwab Guest

    tehn yit chin wrote:
    > 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 <vector> // Did you do this?

    > 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.
    */

    > }
    >
    > 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
    Jeff Schwab, Dec 18, 2003
    #2
    1. Advertising

  3. "tehn yit chin" <> wrote in message
    news:...
    > 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;
    Thomas Wintschel, Dec 18, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. CoolPint
    Replies:
    8
    Views:
    980
    Jeff Schwab
    Dec 14, 2003
  2. JKop
    Replies:
    3
    Views:
    468
  3. Dave
    Replies:
    3
    Views:
    367
    tom_usenet
    Aug 10, 2004
  4. hdixon
    Replies:
    3
    Views:
    644
    hdixon
    Jul 9, 2006
  5. recover
    Replies:
    2
    Views:
    802
    recover
    Jul 25, 2006
Loading...

Share This Page