473,395 Members | 1,629 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

static member function in class template

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
Oct 6 '05 #1
8 14352

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

Oct 6 '05 #2
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" <ml*****@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr 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

Oct 6 '05 #3
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
Oct 6 '05 #4

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)?

Oct 7 '05 #5
|| what is ODR (one definition rule)?
Yep!!

Oct 7 '05 #6

ma740...@gmail.com wrote:
|| what is ODR (one definition rule)?
Yep!!


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

Oct 7 '05 #7
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" <jo*************@hotmail.com> wrote in message
news:JE*****************@newsfe4-gui.ntli.net...
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

Oct 7 '05 #8
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

Oct 7 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Roger Leigh | last post by:
The C++ book I have to hand (Liberty and Horvath, Teach yourself C++ for Linux in 21 Days--I know there are better) states that "static member functions cannot access any non-static member...
7
by: Drew McCormack | last post by:
I have a C++ template class which contains a static variable whose construction registers the class with a map. Something like this: template <typename T> class M { static Registrar<M>...
1
by: ajay.sonawane | last post by:
How to call static member function of template class. For example template <typename T> class A { private: int m_i;
7
by: Ook | last post by:
What am I doing wrong? This code gives a compile error: 'SortedList<T>::insert' : illegal call of non-static member function. I've tried several variations of this, but keep getting the same error....
4
by: MaxMax | last post by:
Now... I have a problem... It's an engineering problem. I have a function, we will call it MyBigFunc. It's a function that can be easily built as a static method, because it is the only function...
1
by: Frederiek | last post by:
Hi, When modifying a data member in a class declaration, the static keyword specifies that one copy of the member is shared by all instances of the class. Does that mean that the address of...
5
by: mast2as | last post by:
Hi guys Here's the class I try to compile (see below). By itself when I have a test.cc file for example that creates an object which is an instance of the class SpectralProfile, it compiles...
13
by: mike b | last post by:
Hello everyone, thanks in advance for your help. I'm new to C++ templates and have run into some issues using member function templates. I have a shared library containing templates that I'm...
17
by: Juha Nieminen | last post by:
As we know, the keyword "inline" is a bit misleading because its meaning has changed in practice. In most modern compilers it has completely lost its meaning of "a hint for the compiler to inline...
5
by: chgans | last post by:
Hi all, I'm having difficulties with some template static member, especially when this member is a template instance, for example: ---- template<typename T> class BaseT { public: static...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.