outside type, outside function

Discussion in 'C++' started by Krzysztof Poc, Feb 3, 2012.

  1. Hi

    I have the following code.

    template <class T>
    class Frame {
    typename T::areaT m_area;

    public:
    typename T::areaT set ( typename T::areaT area ) {}
    };

    class Rectangle {
    public:
    typedef int areaT;
    };

    int main ( void )
    {
    Frame < Rectangle > r;
    return 0;
    }



    I would like to define a Frame<T>::set function outside of class
    definition.
    I did it as follows.

    template <class T>
    typename T::areaT Frame<T>::set ( typename T::areaT area ) {}

    It compiles but I'm not sure whether it is correct.
    Could you please confirm it. In case it isn't correct please type a
    correct
    one.

    thanks
    Krzysztof Poc, Feb 3, 2012
    #1
    1. Advertising

  2. On 2/3/2012 6:33 AM, Krzysztof Poc wrote:
    > I have the following code.
    >
    > template<class T>
    > class Frame {
    > typename T::areaT m_area;
    >
    > public:
    > typename T::areaT set ( typename T::areaT area ) {}


    No 'return'? <shrug> Might be helpful to have it or to change the
    function to 'void'...

    > };
    >
    > class Rectangle {
    > public:
    > typedef int areaT;
    > };
    >
    > int main ( void )
    > {
    > Frame< Rectangle> r;
    > return 0;
    > }
    >
    >
    >
    > I would like to define a Frame<T>::set function outside of class
    > definition.
    > I did it as follows.
    >
    > template<class T>
    > typename T::areaT Frame<T>::set ( typename T::areaT area ) {}


    No 'return'? Seems like a compile error waiting for you to try using
    that function.

    > It compiles but I'm not sure whether it is correct.
    > Could you please confirm it. In case it isn't correct please type a
    > correct
    > one.


    To confirm whether it's the one or not, you should try using it. A
    template is not instantiated until it's used, it's only syntax-parsed
    but no types are verified, etc.

    V
    --
    I do not respond to top-posted replies, please don't ask
    Victor Bazarov, Feb 7, 2012
    #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. heyo
    Replies:
    3
    Views:
    887
    Dan Pop
    Apr 1, 2004
  2. pete
    Replies:
    4
    Views:
    785
    Dan Pop
    Apr 2, 2004
  3. Yevgen Muntyan

    #define ALLOCIT(Type) ((Type*) malloc (sizeof (Type)))

    Yevgen Muntyan, Feb 9, 2007, in forum: C Programming
    Replies:
    10
    Views:
    883
    Yevgen Muntyan
    Feb 13, 2007
  4. Replies:
    1
    Views:
    2,668
    =?ISO-8859-1?Q?Stefan_N=E4we?=
    Jan 9, 2006
  5. kj
    Replies:
    5
    Views:
    398
Loading...

Share This Page