Global Function Error in Partial Specification?

Discussion in 'C++' started by Nephi Immortal, Jan 23, 2013.

  1. I tried to write partial specification on the global function, but the C++ Compiler generates an error. Look at the code and error message below.

    1>d:\omega projects\console application\user types\main.cpp(290): error C2182: 'Test' : illegal use of type 'void'
    1>d:\omega projects\console application\user types\main.cpp(290): error C2998: 'int Test' : cannot be a template definition
    1>d:\omega projects\console application\user types\main.cpp(297): error C2064: term does not evaluate to a function taking 1 arguments

    enum class eTypes
    {
    eA,
    eB,
    ec
    };

    template< eTypes eType, typename Integer_Type >
    class X
    {
    private:
    public:
    template< eTypes eInnerType, typename InnerInteger_Type, InnerInteger_Type Segment >
    class Y
    {
    private:
    X< eInnerType, InnerInteger_Type >& reference;

    Y( X< eInnerType, InnerInteger_Type >& reference ) : reference( reference )
    {
    }

    ~Y()
    {
    }

    Y( const Y< eInnerType, InnerInteger_Type, Segment >& right ) : reference( right.reference )
    {
    }

    Y< eInnerType, InnerInteger_Type, Segment >& operator=( const Y< eInnerType, InnerInteger_Type, Segment >& right )
    {
    reference.value = right.reference.value;
    return *this;
    }

    Y< eInnerType, InnerInteger_Type, Segment >& operator=( Integer_Type value )
    {
    reference.value = value;
    return *this;
    }
    };


    Integer_Type value;

    public:
    X( Integer_Type value ) : value( value )
    {
    }

    ~X()
    {
    }

    X( const X< eType, Integer_Type >& right ) : value( right.value )
    {
    }

    X& operator=( const X< eType, Integer_Type >& right )
    {
    value = right.value;
    return *this;
    }

    Y< eType, Integer_Type, 1 > _1() { return Y< eType, Integer_Type, 1 >( *this ); }

    };

    template< eTypes eInnerType, typename InnerInteger_Type, InnerInteger_Type Segment >
    void Test(
    const X< eInnerType, InnerInteger_Type >::Y< eInnerType, InnerInteger_Type, Segment >& ref
    )
    {
    }

    int main()
    {

    X< eTypes::eA, int > a = 1;

    Test( a._1() );

    return 0;
    }
     
    Nephi Immortal, Jan 23, 2013
    #1
    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. VSK
    Replies:
    1
    Views:
    1,036
    Alvin Bruney
    Jul 29, 2003
  2. Billy
    Replies:
    2
    Views:
    629
    Billy
    Feb 1, 2006
  3. Replies:
    5
    Views:
    724
  4. Thomas Heller
    Replies:
    13
    Views:
    1,137
    Michele Simionato
    Feb 8, 2007
  5. Marek Vondrak
    Replies:
    9
    Views:
    453
    Marek Vondrak
    May 15, 2006
  6. Stefan Ram
    Replies:
    17
    Views:
    576
    James Kanze
    Apr 28, 2009
  7. Kurian Thayil
    Replies:
    3
    Views:
    680
    Terry Reedy
    Jul 18, 2011
  8. Dave Angel
    Replies:
    8
    Views:
    478
    Ian Kelly
    Jul 19, 2011
Loading...