473,408 Members | 2,839 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,408 software developers and data experts.

Function template inside of class template

Consider this:

----SNIP----
template<typename T>
class
foo
{
public:

template<typename Svoid f(S s) { }
};

// ???

// template<typename T>
// void
// foo<T>::f<S>(S s)
// {

// }

int main()
{
foo<intf;

f.f<float>(1.0f);

return 0;
}
----SNIP----

That code works, but how do I write the function definition outside of the
class? I cannot get the code to compile, always some syntax error.

Arne

--
[--- PGP key FD05BED7 --- http://www.root42.de/ ---]
Dec 19 '06 #1
1 1361
The code below works:
template<typename T>
class
foo
{
public:

template<typename Svoid f(S s);
};

// ???

template<typename T>
template<typename S>
void
foo<T>::f(S s)
{

}

int main()
{
foo<intf;

f.f<float>(1.0f);

return 0;
}
--
[--- PGP key FD05BED7 --- http://www.root42.de/ ---]
Dec 19 '06 #2

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

Similar topics

2
by: Ruben Campos | last post by:
I have a problem with a template function that is declared as a friend of a template class. I'll first show the exact problem with source code: // MyClass.hpp template <typename T> class...
7
by: miben | last post by:
OK, this is tricky. I have a function inside a template that returns a pointer to a function whose space is declared as, "void Function(void)". To declare this, i use: template <typename...
7
by: quarup | last post by:
I want to specialize a template function that lives inside a class, but am getting a compile error in VS.net 2003. Here's my code: template <class T> class A { public: template <class U> void...
8
by: coosa | last post by:
Dear all, I have the following code: #include <iostream> #include <string> #include <sstream> using namespace std;
4
by: fdmfdmfdm | last post by:
I have the following code: #include <iostream> #include <cstdlib> #include <cassert> using namespace std; template <class T> class Stack{ public: enum{DefaultStack = 10, EmptyStack = -1};
5
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...
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...
21
by: H9XLrv5oXVNvHiUI | last post by:
Hi, I have a question about injecting friend functions within template classes. My question is specific to gcc (version 3.4.5) used in combination with mingw because this code (or at least code...
5
by: Daniel T. | last post by:
The goal is to make a friend function of an inner template class... template < typename T > class Foo { public: class Bar { friend bool operator==( const typename Foo<T>::Bar& lhs, const...
7
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...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
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
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...
0
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.