VC 2005 - templates - partial specialization

Discussion in 'C++' started by VB, Jun 26, 2006.

  1. VB

    VB Guest

    Hi,
    I was attempting to implement partial specialization using VC 2005.
    However i cannot get my code to compile :( .. Can you please help me?


    template <typename TYPE1>
    class myClass<TYPE1, int>
    //C2143: syntax error : missing ';' before '<'
    //C2059: syntax error : '<'
    {//C2143: syntax error : missing ';' before '{'
    //error C2447: '{' : missing function header (old-style formal list?)
    private:
    TYPE1 xUnspecifiedParameter;
    int xSpecifiedParameter;
    public:
    myClass(TYPE1 xUnspecifiedParameter, int xSpecifiedParameter):
    xUnspecifiedParameter(xType1),
    xSpecifiedParameter(xInt)
    {}

    };

    if i remove <TYPE1, int> from class myClass<TYPE1, int> the compiler
    errors go away but instantiating myclass causes errors ...
    myClass<int,int> myInstance(2,3);
    the compiler complains
    error C2977: 'myClass' : too many template arguments
    error C2514: 'myClass' : class has no constructors
     
    VB, Jun 26, 2006
    #1
    1. Advertising

  2. VB

    Noah Roberts Guest

    VB wrote:
    > Hi,
    > I was attempting to implement partial specialization using VC 2005.
    > However i cannot get my code to compile :( .. Can you please help me?


    Where is the definition of myClass? We need that part to be able to
    help you.
    >
    >
    > template <typename TYPE1>
    > class myClass<TYPE1, int>


    This is partial specialization of some previously defined and currently
    unknown type.

    > //C2143: syntax error : missing ';' before '<'
    > //C2059: syntax error : '<'
    > {//C2143: syntax error : missing ';' before '{'
    > //error C2447: '{' : missing function header (old-style formal list?)
    > private:
    > TYPE1 xUnspecifiedParameter;
    > int xSpecifiedParameter;
    > public:
    > myClass(TYPE1 xUnspecifiedParameter, int xSpecifiedParameter):
    > xUnspecifiedParameter(xType1),
    > xSpecifiedParameter(xInt)
    > {}
    >
    > };
    >
    > if i remove <TYPE1, int> from class myClass<TYPE1, int> the compiler
    > errors go away but instantiating myclass causes errors ...
    > myClass<int,int> myInstance(2,3);
    > the compiler complains
    > error C2977: 'myClass' : too many template arguments
    > error C2514: 'myClass' : class has no constructors
     
    Noah Roberts, Jun 26, 2006
    #2
    1. Advertising

  3. VB

    VB Guest

    Noah Roberts wrote:

    I read about partial specializations again. Now i understand them
    better. I had misinterpreted their usage.

    thanks.
     
    VB, Jun 26, 2006
    #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. Shekhar
    Replies:
    1
    Views:
    505
    Alf P. Steinbach
    Apr 8, 2004
  2. JKop
    Replies:
    3
    Views:
    521
  3. Joseph Turian
    Replies:
    2
    Views:
    492
  4. recover
    Replies:
    2
    Views:
    857
    recover
    Jul 25, 2006
  5. ld
    Replies:
    8
    Views:
    333
Loading...

Share This Page