static member function in class template

  • Thread starter Martin Vorbrodt
  • Start date
M

Martin Vorbrodt

SO i have a class:

template<typename T>
class Vector {
public:
static const Vector<T> UNIT_X();
};

template<typename T>
static const Vector<T> UNIT_X() {
static const Vector<T> unit_x(1,0,0);
return unit_x;
}

GCC 3.4 tell me i can't declare UNIT_X member function to have static
linkage.

How do i go about having such static function.

I want to be able to do Vector<int>::UNIX_X();

Please help.

Martin
 
M

mlimber

Martin said:
SO i have a class:

template<typename T>
class Vector {
public:
static const Vector<T> UNIT_X();
};

template<typename T>
static const Vector<T> UNIT_X() {

Try this line instead:

const Vector said:
static const Vector<T> unit_x(1,0,0);
return unit_x;
}

GCC 3.4 tell me i can't declare UNIT_X member function to have static
linkage.

How do i go about having such static function.

I want to be able to do Vector<int>::UNIX_X();

Please help.

Martin

Cheers! --M
 
M

Martin Vorbrodt

of course, thanks! silly me.

now another thing. the static function must be defined in the header file as
well right? doesn't that violate ODR?

martin
 
J

John Harrison

Martin said:
of course, thanks! silly me.

now another thing. the static function must be defined in the header file as
well right? doesn't that violate ODR?

templates are an exception to ODR.

john
 
M

Martin Vorbrodt

Even static members of templates? Well, I believe it, the code works, but...
feels dirty. Static functions definitions in header files... I guess export
would fix that. Too bad my compiler doesn't this so;)

Anyone knows a 100% conforming compiler? Is there one in works?

Thanx
 
K

Kai-Uwe Bux

a) please don't top post.

Martin said:
Even static members of templates? Well, I believe it, the code works,
but... feels dirty. Static functions definitions in header files...

Why dirty? I consider support for separate compilation more an issue of
speeding up the built process and not that much an issue of code
organization.

I guess export would fix that. Too bad my compiler doesn't this so;)

Anyone knows a 100% conforming compiler? Is there one in works?

Check out http://www.comeaucomputing.com/


Best

Kai-Uwe Bux
 

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,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top