注册 登录
编程论坛 C++教室

如何定义f1这个变量

hffjhhh 发布于 2021-04-09 13:03, 1625 次点击
以下代码显示这个错误:
[Error] 'f1' was not declared in this scope
该如何定义f1这个变量?代码如下:
程序代码:
#include<iostream>
using namespace std;
void func(int x,int y){
    cout<<x<<" "<<y;
}
int main(){
    auto f1=bind(func,_1,_2);
    f1(3,6);
    return 0;
}
3 回复
#2
rjsp2021-04-09 14:16
懒得问为什么了

程序代码:
#include <iostream>
#include <functional>
using namespace std;
using namespace std::placeholders;

void func( int x, int y ) {
    cout << x << ' ' << y;
}

int main( void )
{
    auto f1 = bind(func,_1,_2);
    f1( 3, 6 );
}
#3
hffjhhh2021-04-09 20:58
以下是引用rjsp在2021-4-9 14:16:17的发言:

懒得问为什么了

#include <iostream>
#include <functional>
using namespace std;
using namespace std::placeholders;

void func( int x, int y ) {
    cout << x << ' ' << y;
}

int main( void )
{
    auto f1 = bind(func,_1,_2);
    f1( 3, 6 );
}

这一行又产生新的错误:
using namespace std::placeholders;

[Error] 'placeholders' is not a namespace-name
[Error] expected namespace-name before ';' token
#4
rjsp2021-04-10 00:45
如果标准的C++代码不能编译成功,那你就要想一想是不是编译器的问题,比如,是否用的编译器太老旧了。
1