由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - C++ template
相关主题
一个C++ template的问题C++ linking 弱问 (one file)
templateC++ template question
问个c++的template的问题一个关于C++ template和overload的问题
Cannot use my own container as the underlying container of a stack? (c++)C++ template function type
compile errortemplate 类的继承问题
c++ template question:C++ class template specialization question
C++ template question今天没有上班,说一个FEATURE吧,concept lite
请问这是什么错误呀const_reverse_iterator和reverse_iterator有什么区别? (转载)
相关话题的讨论汇总
话题: template话题: mt话题: typename话题: const话题: compiler
进入Programming版参与讨论
1 (共1页)
b******n
发帖数: 592
1
0 vector a;
1 C<0>(a); // container
I tried to implement C as
template
class C{
const T & mT;
public:
C(const T& t) : mT(t) {};
}
Compiler always complains about T is missing in 1. Is there any way to get
around this?
e****d
发帖数: 895
2
Use a template function to generate C<>.

【在 b******n 的大作中提到】
: 0 vector a;
: 1 C<0>(a); // container
: I tried to implement C as
: template
: class C{
: const T & mT;
: public:
: C(const T& t) : mT(t) {};
: }
: Compiler always complains about T is missing in 1. Is there any way to get

s*w
发帖数: 729
3
你的 vector 没类型啊? 貌似你想做的是 template specification. N 也没用上啊,
去了得了

【在 b******n 的大作中提到】
: 0 vector a;
: 1 C<0>(a); // container
: I tried to implement C as
: template
: class C{
: const T & mT;
: public:
: C(const T& t) : mT(t) {};
: }
: Compiler always complains about T is missing in 1. Is there any way to get

t****t
发帖数: 6806
4
you can not let compiler deduce template parameter when you name a typename.
as someone said, you need a generator:
template
C gen_c(const T& t) { return C(t); }
then you can let compiler deduce:
auto ca=gen_c<0>(a);
this technique is widely used in STL, for example binder1st (class) and
bind1st (generator).

【在 b******n 的大作中提到】
: 0 vector a;
: 1 C<0>(a); // container
: I tried to implement C as
: template
: class C{
: const T & mT;
: public:
: C(const T& t) : mT(t) {};
: }
: Compiler always complains about T is missing in 1. Is there any way to get

b******n
发帖数: 592
5
I did use a generator function. didn't like it though. thought there is an
other way to get around it. thanks. every time I thought I know C++, a test
shows there are much to learn.

typename.

【在 t****t 的大作中提到】
: you can not let compiler deduce template parameter when you name a typename.
: as someone said, you need a generator:
: template
: C gen_c(const T& t) { return C(t); }
: then you can let compiler deduce:
: auto ca=gen_c<0>(a);
: this technique is widely used in STL, for example binder1st (class) and
: bind1st (generator).

1 (共1页)
进入Programming版参与讨论
相关主题
const_reverse_iterator和reverse_iterator有什么区别? (转载)compile error
一个 C++ STL base type 的问题c++ template question:
a c++ questionC++ template question
文一个简单的c++请问这是什么错误呀
一个C++ template的问题C++ linking 弱问 (one file)
templateC++ template question
问个c++的template的问题一个关于C++ template和overload的问题
Cannot use my own container as the underlying container of a stack? (c++)C++ template function type
相关话题的讨论汇总
话题: template话题: mt话题: typename话题: const话题: compiler