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. Advertisements

  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. Advertisements

  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. Advertisements

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. Chandra Shekhar Kumar

    template partial specialization

    Chandra Shekhar Kumar, Jun 24, 2003, in forum: C++
    Replies:
    17
    Views:
    3,225
    tom_usenet
    Jun 25, 2003
  2. Philip Lawatsch

    Partial Specialization workaround

    Philip Lawatsch, Jul 16, 2003, in forum: C++
    Replies:
    9
    Views:
    539
    Philip Lawatsch
    Jul 16, 2003
  3. Alexander Stippler

    partial specialization of function template

    Alexander Stippler, Aug 15, 2003, in forum: C++
    Replies:
    1
    Views:
    626
    Rob Williscroft
    Aug 15, 2003
  4. Shekhar
    Replies:
    1
    Views:
    600
    Alf P. Steinbach
    Apr 8, 2004
  5. JKop
    Replies:
    3
    Views:
    705
  6. Joseph Turian
    Replies:
    2
    Views:
    693
  7. recover
    Replies:
    2
    Views:
    1,083
    recover
    Jul 25, 2006
  8. ld
    Replies:
    8
    Views:
    487
Loading...