473,883 Members | 1,663 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

pullzed at static template member function

Jee
Hi,

I want to declare a static template member function inside a non-template class, but MS C compiler always

complains syntax error. I wonder if it is not allowed to do that? I tried SUN Forte compiler, it errored also.

My class is like,

class a{

public:

static template<class T> vector<T> getIntersection (vector<T>&, vector<T>&);

};

Could you point me what's wrong here?

Jul 19 '05 #1
6 8249
On Fri, 26 Sep 2003 12:23:12 -0600, Jee wrote:
Hi,

I want to declare a static template member function inside a non-template class, but MS C compiler always

complains syntax error. I wonder if it is not allowed to do that? I tried SUN Forte compiler, it errored also.

My class is like,

class a{

public:

static template<class T> vector<T> getIntersection (vector<T>&, vector<T>&);

};

Could you point me what's wrong here?


class a
{
public:
template<class T>
static vector<T> getIntersection (vector<T>&, vector<T>&);
};

Jul 19 '05 #2
Jee
Simon Saunders wrote:
On Fri, 26 Sep 2003 12:23:12 -0600, Jee wrote:
Hi,

I want to declare a static template member function inside a non-template class, but MS C compiler always

complains syntax error. I wonder if it is not allowed to do that? I tried SUN Forte compiler, it errored also.

My class is like,

class a{

public:

static template<class T> vector<T> getIntersection (vector<T>&, vector<T>&);

};

Could you point me what's wrong here?


class a
{
public:
template<class T>
static vector<T> getIntersection (vector<T>&, vector<T>&);
};


I tried this, I got the same error, in MSC the error is
error C2143: syntax error: missing ';' before '<'.

and in Forte the error is
Templates can only declare class and function.
Still puzzled...
Jul 19 '05 #3
"Jee" <je*@hotmail.co m> wrote in message
news:3F******** *******@hotmail .com...
Simon Saunders wrote:

class a
{
public:
template<class T>
static vector<T> getIntersection (vector<T>&, vector<T>&);
};


I tried this, I got the same error, in MSC the error is
error C2143: syntax error: missing ';' before '<'.

and in Forte the error is
Templates can only declare class and function.


Did you #include <vector>? Did you type "using namespace std;" or "using
std::vector;"?

This complete example compiles for me with Visual C++ .NET (2002):

#include <vector>

using std::vector;

class a
{
public:
template<class T>
static vector<T> getIntersection (vector<T>&, vector<T>&);
};

--
Russell Hanneken
rg********@pobo x.com
Remove the 'g' from my address to send me mail.

Jul 19 '05 #4
right code is:
class a{

public:

template<class T> static vector<T> getIntersection (vector<T>&, vector<T>&);

};

Jee <je*@hotmail.co m> wrote in message news:<3F******* ********@hotmai l.com>...
Hi,

I want to declare a static template member function inside a non-template class, but MS C compiler always

complains syntax error. I wonder if it is not allowed to do that? I tried SUN Forte compiler, it errored also.

My class is like,

class a{

public:

static template<class T> vector<T> getIntersection (vector<T>&, vector<T>&);

};

Could you point me what's wrong here?

--

Jul 19 '05 #5
DarkSpy wrote:
right code is:

<snip>

Please don't top-post. Read section 5 of the FAQ for posting guidelines.

http://www.parashift.com/c++-faq-lite/

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.

Jul 19 '05 #6
"Russell Hanneken" <rg********@pob ox.com> wrote in message news:<qt******* **********@news read4.news.pas. earthlink.net>. ..
"Jee" <je*@hotmail.co m> wrote in message
news:3F******** *******@hotmail .com...
Simon Saunders wrote:

class a
{
public:
template<class T>
static vector<T> getIntersection (vector<T>&, vector<T>&);
};


I tried this, I got the same error, in MSC the error is
error C2143: syntax error: missing ';' before '<'.


sorry about my answer with above.

if you got error, please check the MSC's version, maybe it is not
enough modern to compile this code :-) or check the STL, please code:
#include <vector>
using namespace std; or using std::vector;
Jul 19 '05 #7

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

Similar topics

1
1868
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
32108
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. template <typename T> class SortedList { public: void insert( T item); // Write this
5
1913
by: Pedro Sousa | last post by:
Hi, I'm trying to create an template class that represent points in all possible dimensions, what I've made until now is #ifndef _POINT_HPP_ #define _POINT_HPP_ #include <vector>
2
1834
by: Amadeus W. M. | last post by:
I have a bunch of templated functions: template <class Type_t> double f2(Type_t x) { return 2*x; } template <class Type_t> double f3(Type_t x) { return 3*x; }
2
2325
by: pookiebearbottom | last post by:
Just trying to learn some things about templates. Was wondering how boost::tupple really works, but the headers were a bit confusing to me. I know you get do something like the following, just want to know how it works with the overloading of get<>(). boost::tupple<int,doubletup(1,2.0); double d=tup.get<2>(); // equal 2.0 // simple set up,
5
2276
by: StephQ | last post by:
This is from a thread that I posted on another forum some days ago. I didn't get any response, so I'm proposing it in this ng in hope of better luck :) The standard explanation is that pointer to functions are hard to inline for the compiler, and so you won't be able to avoid function call overhead. This is an important aspect when you are calling a function very frequently for evaluation reason: think of the problem of performing...
13
6613
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 trying to use from an executable, compile using gcc 4.1.2. Everything works fine until I try specializing one of the static member function templates in a non-template class. I have a feeling I'm messing up something obvious so before I post a...
2
1864
by: subramanian100in | last post by:
consider the following program #include <iostream> using namespace std; class Rec { public: Rec(int arg = 10) : val(arg) { }
7
3833
by: ghulands | last post by:
I am having trouble implementing some function pointer stuff in c++ An object can register itself for many events void addEventListener(CFObject *target, CFEventHandler callback, uint8_t event); so I declared a function pointer like typedef void (CFObject::*CFEventHandler)(CFEvent *theEvent);
0
9936
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9791
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10846
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10412
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9571
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7123
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5797
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5990
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3231
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.