Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > static member function in class template

Reply
Thread Tools

static member function in class template

 
 
Martin Vorbrodt
Guest
Posts: n/a
 
      10-06-2005
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


 
Reply With Quote
 
 
 
 
mlimber
Guest
Posts: n/a
 
      10-06-2005

Martin Vorbrodt wrote:
> 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<T> 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


Cheers! --M

 
Reply With Quote
 
 
 
 
Martin Vorbrodt
Guest
Posts: n/a
 
      10-06-2005
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



"mlimber" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
>
> Martin Vorbrodt wrote:
> > 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<T> 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

>
> Cheers! --M
>



 
Reply With Quote
 
John Harrison
Guest
Posts: n/a
 
      10-06-2005
Martin Vorbrodt wrote:
> 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
 
Reply With Quote
 
puzzlecracker
Guest
Posts: n/a
 
      10-07-2005

John Harrison wrote:
> Martin Vorbrodt wrote:
> > 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


what is ODR (one definition rule)?

 
Reply With Quote
 
ma740988@gmail.com
Guest
Posts: n/a
 
      10-07-2005
|| what is ODR (one definition rule)?
Yep!!

 
Reply With Quote
 
puzzlecracker
Guest
Posts: n/a
 
      10-07-2005

(E-Mail Removed) wrote:
> || what is ODR (one definition rule)?
> Yep!!


I don't think "Yep" is a definition. Get a life -trol!

 
Reply With Quote
 
Martin Vorbrodt
Guest
Posts: n/a
 
      10-07-2005
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



"John Harrison" <(E-Mail Removed)> wrote in message
news:JEe1f.10302$(E-Mail Removed)...
> Martin Vorbrodt wrote:
>> 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



 
Reply With Quote
 
Kai-Uwe Bux
Guest
Posts: n/a
 
      10-07-2005
a) please don't top post.

Martin Vorbrodt wrote:

> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to use the template member function of a template in the memberfunction of another template class? Peng Yu C++ 3 10-26-2008 03:51 PM
Can a static member function access non-static member? dolphin C++ 3 12-05-2007 12:39 PM
What is the correct grammar to make a function call by using static member data which is a pointer to a ordinary class member function? zaeminkr@gmail.com C++ 3 07-06-2007 12:50 PM
template class static template type member address allocation Frederiek C++ 1 09-14-2006 03:10 PM
parse error in gcc but success in vc.net, call a non_template class's template member function from a template class's member function! ken C++ 2 06-28-2005 06:57 AM



Advertisments