template definition

Discussion in 'C++' started by antani, Feb 20, 2007.

  1. antani

    antani Guest

    template <typename T>
    class tt
    {
    vector<T> vect;
    inline void add(const T & t);
    }

    Can I define the member function "inline void add(const T & t)"
    outside the class interface in the header file?How?
    Thanks in advance.
    antani, Feb 20, 2007
    #1
    1. Advertising

  2. On Feb 20, 12:49 pm, "antani" <> wrote:
    > template <typename T>
    > class tt
    > {
    > vector<T> vect;
    > inline void add(const T & t);
    >
    > }
    >
    > Can I define the member function "inline void add(const T & t)"
    > outside the class interface in the header file?How?


    Not sure I understand you correctly, but is this what you want?

    template <typename T>
    class tt
    {
    vector<T> vect;
    inline void add(const T & t);

    };

    template<typename T>
    void tt::add(const T& t)
    {
    // do stuff
    }

    --
    Erik Wikström
    =?iso-8859-1?q?Erik_Wikstr=F6m?=, Feb 20, 2007
    #2
    1. Advertising

  3. antani

    Guest

    On Feb 20, 2:11 pm, "Erik Wikström"
    <> wrote:
    > On Feb 20, 12:49 pm, "antani" <>
    > wrote:
    >
    > > template <typename T>
    > > class tt
    > > {
    > > vector<T> vect;
    > > inline void add(const T & t);

    >
    > > }

    >
    > > Can I define the member function "inline void
    > > add(const T & t)" outside the class interface in the
    > > header file?How?

    >
    > template<typename T>
    > void tt::add(const T& t)
    > {
    > // do stuff
    > }


    Shouldn't this be more like this?

    template<typename T>
    void tt<T>::add(const T& t)
    {
    // do stuff
    }

    --
    Pavel Lepin
    , Feb 20, 2007
    #3
  4. On Feb 20, 2:06 pm, wrote:
    > On Feb 20, 2:11 pm, "Erik Wikström"
    >
    >
    >
    > <> wrote:
    > > On Feb 20, 12:49 pm, "antani" <>
    > > wrote:

    >
    > > > template <typename T>
    > > > class tt
    > > > {
    > > > vector<T> vect;
    > > > inline void add(const T & t);

    >
    > > > }

    >
    > > > Can I define the member function "inline void
    > > > add(const T & t)" outside the class interface in the
    > > > header file?How?

    >
    > > template<typename T>
    > > void tt::add(const T& t)
    > > {
    > > // do stuff
    > > }

    >
    > Shouldn't this be more like this?
    >
    > template<typename T>
    > void tt<T>::add(const T& t)
    > {
    > // do stuff
    >
    > }


    Oops, sorry, yes that is correct.

    --
    Erik Wikström
    =?iso-8859-1?q?Erik_Wikstr=F6m?=, Feb 20, 2007
    #4
    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. Jianli Shen
    Replies:
    1
    Views:
    567
    Victor Bazarov
    Mar 13, 2005
  2. BigMan
    Replies:
    3
    Views:
    1,418
    BigMan
    Apr 22, 2005
  3. =?iso-8859-1?q?Erik_Wikstr=F6m?=
    Replies:
    5
    Views:
    2,303
    =?iso-8859-1?q?Erik_Wikstr=F6m?=
    Dec 14, 2006
  4. Hendrik Schober
    Replies:
    16
    Views:
    567
    Hendrik Schober
    Sep 4, 2007
  5. Pierre Yves
    Replies:
    2
    Views:
    473
    Pierre Yves
    Jan 10, 2008
Loading...

Share This Page