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

partial template specialization...

Hi everyone, I've been trying to compile a very simple code for
template partial specializatoin. I can't compile this code! what is
wrong with it? I'm using the g++ compiler.

#include <vector>
#include <iostream>

using namespace std;

template <class T, class U>
class ClassA
{
T t_;
U u_;

public:

ClassA() { t_ = 0; u_ = 0; }

void print()
{
cout<<"T -"<<t_<<endl;
cout<<"U -"<<u_<<endl;
}

};

template <class T>
void ClassA<T,int>::print()
{
cout<<"T -"<<t_<<endl;
cout<<"U is an integer!"<<endl;

}

int main()
{
ClassA<double,intca;
ca.print();

return 0;
}

main2.cxx:25: error: invalid use of undefined type 'class ClassA<T,
int>'
main2.cxx:8: error: declaration of 'class ClassA<T, int>'
main2.cxx:25: error: template definition of non-template 'void
ClassA<T, int>::print()'
main2.cxx: In member function 'void ClassA<T, int>::print()':
main2.cxx:27: error: 't_' was not declared in this scope

Nov 4 '06 #1
1 1307
aaragon wrote:
Hi everyone, I've been trying to compile a very simple code for
template partial specializatoin. I can't compile this code! what is
wrong with it? I'm using the g++ compiler.
You can't have partial specialisation of a class member, you can define
a specialisation of a member, or a partial specialisation of a class.

--
Ian Collins.
Nov 4 '06 #2

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

Similar topics

8
by: Agent Mulder | last post by:
Hi group, I have a problem with partial template specialization. In the code below I have a template struct Music with one method, play(), and three kinds of music, Jazz, Funk and Bach. When I...
6
by: Alex | last post by:
I've a problem with following simple code (not really usefull): //--------------------------------------------------------------------------- #pragma hdrstop #include "stdio.h" #include...
1
by: mrstephengross | last post by:
I'm trying to specialize one template argument in a member function that takes two template arguments. I've seen other posts on this group indicating that it's not possible, but I wanted to make...
5
by: __PPS__ | last post by:
Hello, I want to write specialized method for a class: template<class A, class B> class xxx{ A a; B b; operator bool()const{ a==b; } };
6
by: rincewind | last post by:
Hi, can anybody summarise all options for partial template specialization, for all kind of parameters (type, nontype, template)? I *think* I understand options for partial specialization on...
1
by: toton | last post by:
Hi, I am doing some template specialization for a template class, where specialization is done on a member function. I am not able to get exact syntax for it. The code is give as below, enum...
5
by: cpunerd | last post by:
I'm confused as to the syntax for partial template specialization. Below is a very small example. Can someone tell me what I should do to make this compile properly on an ISO-compliant compiler? ...
1
by: vectorizor | last post by:
Hello, I've got a template function: template <typename U, typename T> void func(ColourImage<U&input,GrayImage<T&out_r, GrayImage<T> &out_g, GrayImage<T&out_b); and I would like to...
1
by: Martin | last post by:
I'm trying to make a partial specialization of a class of mine. Can someone please tell me what's wrong with the following code? GCC gives me the error "invalid use of undefined type "class X<int,...
1
by: Ioannis Gyftos | last post by:
Hello, First the code :) /////////////////////////////////////////////////////////////////////////////////// // in another header file namespace LJC{
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?
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
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
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...
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
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,...
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.