C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

question about Partial Template Specialization

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
Leon Wu
Guest





PostPosted: Mon Nov 13, 2006 10:10 am    Post subject: question about Partial Template Specialization Reply with quote



I have some code like following:
template<class T>
class A
{
public:
A(T& t) : m_b(t){};
void Func()
{
m_b.DoSome();
};
private:
B<t> m_b;
};
---------------------------------------
template<class T>
class B
{
public:
void DoSome() {
cout << "type t";
};
private:
T &t;
};
template<>
void B<int>::DoSome()
{
cout << "type int";
}
---------------------------------------
main()
{
A<int> a;
a.Func();
}

the output is "type t" instead of "type int", why?! any help is
appericiated.
Back to top
Gianni Mariani
Guest





PostPosted: Mon Nov 13, 2006 10:10 am    Post subject: Re: question about Partial Template Specialization Reply with quote



Leon Wu wrote:
Quote:
I have some code like following:
template<class T
class A
{
public:
A(T& t) : m_b(t){};
void Func()
{
m_b.DoSome();
};
private:
B<t> m_b;
};
---------------------------------------
template<class T
class B
{
public:
void DoSome() {
cout << "type t";
};
private:
T &t;
};
template
void B<int>::DoSome()
{
cout << "type int";
}
---------------------------------------
main()
{
A<int> a;
a.Func();
}

the output is "type t" instead of "type int", why?! any help is
appericiated.


Please post a complete compilable program...

After fixing a number of compile errors you get this -
this says "type int"

#include <iostream>

template<class T>
class B;

template<class T>
class A
{
public:
A() {};
A(T& t) : m_b(t){};
void Func()
{
m_b.DoSome();
};
private:
B<T> m_b;
};
//---------------------------------------
template<class T>
class B
{
public:
void DoSome() {
std::cout << "type t";
};
private:
T &t;
};
template<>
void B<int>::DoSome()
{
std::cout << "type int";
}
//---------------------------------------
int main()
{
A<int> a;
a.Func();
}
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.