473,503 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

member templated definitions out of class scope

Hi All,

With gcc (3 or 4) the member template definition out of class scope
below compiles fine. But with Sun's CC 5.9, it fails with:

"main.cpp", line 7: Error: Could not find a match for Foo<T,
Policy<struct>>::bar<Foo<T, Policy<struct>>::U>(U).

This seems like a bug to me, has anyone else encountered this? Is
there any workaround beside putting the definition inside the class
decl?

Thanks much.

$ CC -V
CC: Sun C++ 5.9 Linux_i386 Patch 124865-01 2007/07/30

//main.h
#include <iostream>
#include <string>

template <typename T, template <classclass Policy >
struct Foo : Policy<T>
{
template <typename Uvoid bar(U u);
};

template <typename T>
class double_creator
{
T m_data;
};

//main.cpp
#include "main.h"
using namespace std;

template <typename T, template <classclass Policy >
template <typename U>
void Foo<T, Policy>::bar(U u)
{
cout << "Hello world " << u.c_str() << sizeof(T) << endl;
}

Nov 8 '07 #1
1 1311
George wrote:
With gcc (3 or 4) the member template definition out of class scope
below compiles fine. But with Sun's CC 5.9, it fails with:

"main.cpp", line 7: Error: Could not find a match for Foo<T,
Policy<struct>>::bar<Foo<T, Policy<struct>>::U>(U).

This seems like a bug to me, has anyone else encountered this? Is
there any workaround beside putting the definition inside the class
decl?
Consider asking in the newsgroup for Sun's compiler (one with "solaris"
in the name, maybe). You seem to have an issue with that particular
compiler, which makes it OT here.
>
Thanks much.

$ CC -V
CC: Sun C++ 5.9 Linux_i386 Patch 124865-01 2007/07/30

//main.h
#include <iostream>
#include <string>

template <typename T, template <classclass Policy >
struct Foo : Policy<T>
{
template <typename Uvoid bar(U u);
};

template <typename T>
class double_creator
{
T m_data;
};

//main.cpp
#include "main.h"
using namespace std;

template <typename T, template <classclass Policy >
template <typename U>
void Foo<T, Policy>::bar(U u)
{
cout << "Hello world " << u.c_str() << sizeof(T) << endl;
}
Seems OK to me. Are you sure you're _using_ that function in the
same module (main.cpp), though? Because if you aren't the compiler
may not be able to link it correctly...

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Nov 8 '07 #2

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

Similar topics

9
2292
by: Jon Wilson | last post by:
I have a class which needs to accumulate data. The way we get this data is by calling a member function which returns float on a number of different objects of different type (they are all the...
4
1844
by: Lionel B | last post by:
Greetings, The following code: <code> template<typename T> class A { protected:
6
1511
by: Dan Huantes | last post by:
I was presented a problem today where a class had member variable that was an object of a templated class. The class wanted to instantiate the object as a private member variable and call a...
5
3585
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...
5
2021
by: Steven T. Hatton | last post by:
If find the following excerpt from the Standard a bit confusing: <quote> 3.3.6 - Class scope -1- The following rules describe the scope of names declared in classes. 1) The potential scope...
3
2900
by: toton | last post by:
Hi, I want to specialize template member function of a template class . It is creating some syntax problem .... Can anyone say how to do it ? The class is something like this template<typename...
2
2292
by: Ninereeds | last post by:
I'm messing around with using mixin-layers (look for papers by Yannis Smaragdakis and Don Batory) to define data structures. One issue is that nodes tend to have pointers to other nodes - the...
2
7676
by: Barry | last post by:
The following code compiles with VC8 but fails to compiles with Comeau online, I locate the standard here: An explicit specialization of any of the following:
15
7838
by: akomiakov | last post by:
Is there a technical reason why one can't initialize a cost static non- integral data member in a class?
0
7203
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
7087
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...
1
6993
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
7462
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
4675
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...
0
3168
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...
0
3156
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
737
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
383
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...

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.