我有一个非常简单的源读取文件描述符挂起.任何人都可以注意到代码有问题吗?
第一个是有问题的来源,第二个是在网络上找到的工作来源.两个来源几乎相同.
第一来源
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
int main(int argc, char ** argv) {
int n, in;
char buf[1024];
if ((in = open(argv[1], O_RDONLY)<0)) {
perror(argv[1]);
return -1;
}
while((n = read(in, buf, sizeof(buf))) > 0 ) { //HANGS at THIS LINE!!!!!!!!!!!
printf("TEST\n");
}
close(in);
return 0;
}
Run Code Online (Sandbox Code Playgroud)第二工作源来自网上
/*
* ============================================================================
* Name : sp_linux_copy.c
* Author : Marko Martinovi?
* Description : Copy input file into output file
* ============================================================================ …Run Code Online (Sandbox Code Playgroud)我正在测试下面的代码,但编译器在我用C++ 11编译时说:
error: call of overloaded ‘func_A(int)’ is ambiguous
谁能解释一下?
这是代码:
template<typename T> class MC {
public:
void func_A(int a, T initvalue = T()) {}
void func_A(int a) {}
void func_B(int b, T) {}
void func_B(int b) {}
};
int main(void) {
MC<int> mc;
mc.func_A(1); // error: detects call of overloaded
mc.func_A(1,2); // OK
mc.func_B(10); // OK
mc.func_B(10,11); // OK
return 0;
}
Run Code Online (Sandbox Code Playgroud)
完整的编译消息:
$ g++ -std=c++11 test.cpp
test.cpp: In function ‘int main()’:
test.cpp:12:16: error: call of overloaded ‘func_A(int)’ is …Run Code Online (Sandbox Code Playgroud)