关于template中operator的问题
#include<iostream>
using namespace std;
template<class T> struct plus{
T operator()(const T& x,const T& y)const{
return x+y;
}
};
template<class T> struct minus{
T operator()(const T& x,const T& y)const{
return x-y;
}
};
int main(){
plus<int> plusobj; //在编译时说plus没定义。
minus<int> minusobj;
cout<<plusobj(3,5)<<endl;
cout<<minusobj(3,5)<<endl;
cout<<plus<int>()(43,50)<<endl;//这两句的语法比较诡异,是将plus<int>()当成一个函数名了吗?
cout<<minus<int>()(43,50)<<endl;
}rt,上面的程序在devC++中编译出问题如下:
14 E:\skin\学习\C++相关\stl源码剖析\opertor多载化.cpp `plus' undeclared (first use this function)
14 E:\skin\学习\C++相关\stl源码剖析\opertor多载化.cpp expected primary-expression before "int"
。。。。。。。。。。。。。。最近被template搞的很崩溃,想学学stl所以先看了看template。应该怎样学stl最好呢,大牛们给给建议吧。
...全文
相关推荐
[SGI]Standard_Template_Library_Programmers_Guide.zip
[SGI]Standard_Template_Library_Programmers_Guide.zip
C++完美实现Singleton模式
C++完美实现Singleton模式
STL Tutorial and Reference Guide_ C++ Programming with the Standard Template Library.zip
STL Tutorial and Reference Guide_ C++ Programming with the Standard Template Library.zip
Vue常见问题及解决
Vue常见问题及解决,是公司一个多年前端总结的,都是个人经验之谈
C++ STL迭代器机制剖析.pdf
C++ STL迭代器机制剖析 -- C++经典书籍哦


