我写了一个简短的例子,说明我在这里遇到的困惑:
#include <iostream>
template <typename T>
T Add (T t1, T t2)
{
std::cout << "<typename T>" << std::endl ;
return t1 + t2 ;
}
template <int>
int Add (int n1, int n2)
{
std::cout << "<int>" << std::endl ;
return n1 + n2 ;
}
template <>
int Add (int n1, int n2)
{
std::cout << "<>" << std::endl ;
return n1 + n2 ;
}
int main (void)
{
Add (5, 4) ;
Add <int> (5, 4) …Run Code Online (Sandbox Code Playgroud) 我有一种直觉VS2012这个错了,但我不确定.
看完这个问题之后,我觉得要尝试实现类似的东西.
我的版本在Visual Studio 2012上运行良好,但甚至不在Ideone上编译.
这是我的主界面:
#include <iostream>
#include <string>
template <class In, class Out>
struct Pipe
{
typedef In in_type ;
typedef Out out_type ;
In in_val ;
Pipe (const in_type &in_val = in_type()) : in_val (in_val)
{
}
virtual auto operator () () const -> out_type
{
return out_type () ;
}
};
template <class In, class Out, class Out2>
auto operator>> (const Pipe <In, Out> &lhs, Pipe <Out, Out2> &rhs) -> Pipe <Out, …Run Code Online (Sandbox Code Playgroud)