考虑我有以下代码:
#define _GNU_SOURCE /* See feature_test_macros(7) */
#include <fcntl.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
int main(int argc, char** argv) {
if (argc > 2) {
int fd = open(argv[1], O_CREAT|O_WRONLY, 0777);
size_t size = atoi(argv[2]);
if (fd > 0) {
//int result = fallocate(fd, 0, 0, size);
//printf("itak: %d, errno: %d (%s)\n", result, errno, strerror(errno));
int result = posix_fallocate(fd, 0, size);
printf("itak: %d, errno: %d (%s)\n", result, result, strerror(result));
} else {
printf("failed …Run Code Online (Sandbox Code Playgroud) 我已经阅读了很多关于rvalue和在C++> = 11中返回局部变量的信息.据我所知,"只是按值返回,不要使用move/forward而不添加&&方法签名,编译器将优化它适合你".
好的,我希望它发生:
#include <sstream>
std::stringstream GetStream() {
std::stringstream s("test");
return s;
}
auto main() -> int {
auto s = GetStream();
}
Run Code Online (Sandbox Code Playgroud)
我很好
error: use of deleted function ‘std::basic_stringstream<char>::basic_stringstream(const std::basic_stringstream<char>&)’
return s;
Run Code Online (Sandbox Code Playgroud)
错误.我不明白,为什么它会尝试复制构造函数?不应该使用移动构造函数和c ++ 11中的所有好东西吗?我用"--std = c ++ 14".
我知道这是一个简单的问题,但我用谷歌搜索了一段时间,从我发现的内容来看,我仍然不明白这个问题。我有这个简单的代码:
class X {
public:
X() : x_(42) {};
virtual const long long f() const {
return do_f();
}
protected:
virtual const long long do_f() const {
return x_;
}
long long x_;
};
auto main() -> int {
X x;
x.f();
}
Run Code Online (Sandbox Code Playgroud)
我希望它能够编译,因为我看不到这些方法如何修改 X 的对象。但显然我错过了一些东西,因为:
rakul@lucky-star /tmp $ g++ --std=c++14 -Werror=ignored-qualifiers 1.cpp
1.cpp:6:37: error: type qualifiers ignored on function return type [-Werror=ignored-qualifiers]
virtual const long long f() const {
^
1.cpp:10:40: error: type qualifiers ignored on function return type …Run Code Online (Sandbox Code Playgroud)