outside type, outside function

K

Krzysztof Poc

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
 
V

Victor Bazarov

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 ) {}

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top