首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

关于STL的函数适配器的有关问题,求解决

2012-11-08 
关于STL的函数适配器的问题,求解决各位牛人,刚接触STL,为什么编译错误,我是照着书上打的代码int main(void

关于STL的函数适配器的问题,求解决
各位牛人,刚接触STL,为什么编译错误,我是照着书上打的代码
int main(void)
{
plus<int> p;
binder1st<plus<int>>b=bind1st(p,10);
int m=b(8);
cout<<m<<endl;
return 0;
}
这是错误提示:
CPP_STL.CPP
E:\新建文件夹\CPP_STL\CPP_STL.CPP(276) : error C2146: syntax error : missing ',' before identifier 'b'
E:\新建文件夹\CPP_STL\CPP_STL.CPP(276) : error C2065: 'b' : undeclared identifier
E:\新建文件夹\CPP_STL\CPP_STL.CPP(276) : error C2143: syntax error : missing '>' before ';'
E:\新建文件夹\CPP_STL\CPP_STL.CPP(276) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class std::binder1st<struct std::plus<int> >' (or there is no acceptable conversion)
Error executing cl.exe.

CPP_STL.OBJ - 4 error(s), 0 warning(s)


[解决办法]
没包含 模板库吧
[解决办法]
#include <stdio.h>
#include<iostream>
#include<functional>
using namespace std;
int main(void)
{
plus<int> p;
binder1st<plus<int>>b=bind1st(p,10);
int m=b(8);
cout<<m<<endl;
return 0;
}
我是这样运行的,没问题,可能你运行的时候头文件没有加吧!
[解决办法]
#include <functional>
[解决办法]
binder1st<plus<int>>b
改成
binder1st<plus<int> >b

[解决办法]
你的代码第四行:binder1st<plus<int>> b=bind1st(p,10);
注意b之前有个空格,否则数据类型都没有了。

热点排行