Template Instantiation and member templates.

Discussion in 'C++' started by amparikh@gmail.com, Jan 27, 2006.

  1. Guest

    I have something like this.

    typedef enum TYPES{ X =0, Y,
    Z,
    MAX};

    template <typename T>
    class A
    {
    public:
    typedef T obj;

    A(){ }
    ~A() { }
    template < int N>
    void Open();
    template < int N>
    void Close();
    private:
    obj Object;
    };

    then I have

    template<>
    A<SomePreDefinedObject>::A()
    {
    // call member function of SomePreDefinedObject
    }

    template<>
    template<int N>
    A<SomePreDefinedObject>::Open()
    {
    ASSERT(N < MAX);
    // call member function of SomePreDefinedObject

    }

    template<>
    template<int N>
    A<SomePreDefinedObject>::Close()
    {
    ASSERT(N < MAX);
    // call member function of SomePreDefinedObject
    }


    template<>
    template<>
    A<SomePreDefinedObject>::Open<MAX>()
    {
    // call member function of SomePreDefinedObject
    }

    template<>
    template<>
    A<SomePreDefinedObject>::Close<MAX>()
    {
    // call member function of SomePreDefinedObject
    }

    now in main I have

    main()
    {
    A<SomePreDefinedObject> O;

    O.Lock<MAX>; //everything is fine //line 1

    O.Lock<X>; // I get linker error // Line 2

    }

    Anyone knows why I could be getting linker error for Line 2 whch says
    Lock and Unlock not found? I have the memner template defined for all
    values except MAX and then for MAX it is specialized.

    Thanks.
    , Jan 27, 2006
    #1
    1. Advertising

  2. wrote:
    > I have something like this.
    >
    > [...]
    >
    > now in main I have
    >
    > [...]
    >
    > Anyone knows why I could be getting linker error for Line 2 whch says
    > Lock and Unlock not found? I have the memner template defined for all
    > values except MAX and then for MAX it is specialized.


    Please post _real_ code with which you have troubles. Read FAQ section 5.

    V
    Victor Bazarov, Jan 27, 2006
    #2
    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. JKop
    Replies:
    3
    Views:
    451
  2. Replies:
    5
    Views:
    475
  3. recover
    Replies:
    2
    Views:
    784
    recover
    Jul 25, 2006
  4. Replies:
    1
    Views:
    559
    Salt_Peter
    Dec 25, 2006
  5. Noah Roberts
    Replies:
    6
    Views:
    1,130
    Johannes Schaub (litb)
    Feb 2, 2011
Loading...

Share This Page