仅安装在Windows 7上的IDE.我想创建一个Plain C++项目(非QT项目); 但是我收到一个错误:找不到有效的工具包.当我点击选项 - >套件时,我看到桌面(默认)套件,它没有显示任何错误.
我收到错误是因为我没有安装Qt库吗?如果是这样,有什么办法可以绕过下载/安装并只使用IDE?
以下不编译(非常详细的错误,但基本上"不能重载"和"从'const void*'无效转换为'void*'").我可以理解为什么例如push_back()可能无法编译,因为你无法复制/移入a Foo* const,但为什么不编译:
#include <vector>
using namespace std;
class Foo;
int main()
{
vector<Foo* const> vec;
}
Run Code Online (Sandbox Code Playgroud) 从编译时已知为派生类的类调用虚方法时是否存在性能损失?下面我force_speak用派生类显式调用.
码:
#include <iostream>
#include <array>
#include <memory>
class Base
{
public:
virtual void speak()
{
std::cout << "base" << std::endl;
}
};
class Derived1 : public Base
{
public:
void speak()
{
std::cout << "derived 1" << std::endl;
}
};
template<class B>
void force_speak(std::array<std::unique_ptr<B>, 3>& arr)
{
for (auto& b: arr)
{
b->speak();
}
}
int main()
{
std::array<std::unique_ptr<Derived1>, 3> arr =
{
std::unique_ptr<Derived1>(new Derived1),
std::unique_ptr<Derived1>(new Derived1),
std::unique_ptr<Derived1>(new Derived1)
};
force_speak(arr);
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我有一个查询写在位于/ path/to/query的文件中.如何在不在查询中使用COPY的情况下将输出结果保存到csv文件?我尝试了以下命令,但输出文件的字段用"|"分隔.
psql -U username -d dbname -f /path/to/query -o /path/to/output/file -F ','
Run Code Online (Sandbox Code Playgroud) test1.cpp下面编译,但test2.cpp不编译.两者之间的唯一区别是我Handle::add_it在test1.cpp中的类声明中定义,但在test2.cpp中定义.
test1.cpp: g ++ test1.cpp -o test1 -std = c ++ 11
#include <iostream>
template<typename B>
class Handle
{
public:
decltype(B.operator(int)) add_it(int x)
{
return b(x);
}
B b;
};
struct Add1
{
int operator()(int x)
{
return x + 1;
}
};
int main()
{
Handle<Add1> h;
std::cout << h.add_it(5) << std::endl;
}
Run Code Online (Sandbox Code Playgroud)
test2.cpp: g ++ test2.cpp -o test2 -std = c ++ 11 …
根据优化C++,
对于您确定永远不会抛出异常的函数,使用空的异常规范(即,对声明追加throw()).
如果我知道90%的方法都不会抛出异常怎么办?将throw()附加到所有这些方法似乎是非常规和冗长的.如果没有,有什么好处?或者我在这里误解了什么?
我在这里缺少什么?为什么我不能将向量作为类构造函数的一部分移动?从构造函数中删除 const 也没有帮助。
#include <iostream>
#include <vector>
#include <memory>
using namespace std;
class Bar
{
public:
Bar(const vector<unique_ptr<char>> vec);
vector<unique_ptr<char>> vec_;
};
Bar::Bar(const vector<unique_ptr<char>> vec) :
vec_(move(vec)) //not ok
{
}
int main()
{
vector<unique_ptr<char>> vec;
vec.push_back(unique_ptr<char>(new char('a')));
vec.push_back(unique_ptr<char>(new char('b')));
vec.push_back(unique_ptr<char>(new char('c')));
vector<unique_ptr<char>> vec1 (move(vec)); //ok
Bar bar(vec1);
return 0;
}
Run Code Online (Sandbox Code Playgroud) 底部的代码生成以下编译时错误.如果我使用std::vector<Node>或,错误消失了std::array<unique_ptr<Node>, 3>.有人可以解释一下这是什么意思吗?
在main.cpp中包含的文件中:1:0:
/usr/include/ c++ /4.9/ array:在'struct std :: array'的实例化中:main.cpp:9:23:从这里需要/ usr/include/c ++/4.9/array:97:56:错误:'std :: array <_Tp,_Nm> :: _ M_elems'具有不完整的类型typename _AT_Type :: _ Type _M_elems; ^ main.cpp:3:7:错误:'类节点'类节点的前向声明
#include <array>
class Node
{
public:
Node(Node* parent, int x) : parent_(parent), x_(x) {}
Node* parent_;
int x_;
std::array<Node, 3> children_; // ERROR
};
Run Code Online (Sandbox Code Playgroud) 我想找到最大值Foo并调用inc()它,这是一种非常量方法。当然,在寻找最大值时,我不想创建任何副本或移动,即我不想Foo foo = std::max(foo1, foo2). 我尝试编写自己的最大值,而 g++ 坚持我返回一个 const&。
#include <iostream>
class Foo
{
public:
Foo(int x) : x_(x) { std::cout << "const" << std::endl; }
Foo(const Foo& foo) : x_(foo.x_) { std::cout << "copy const" << std::endl; }
Foo(Foo&& foo) : x_(foo.x_) { std::cout << "move const" << std::endl; }
bool operator< (const Foo& foo) const { return x_ < foo.x_; }
bool operator> (const Foo& foo) const { return x_ > foo.x_; …Run Code Online (Sandbox Code Playgroud) 我知道已经有人问过这个问题,但为什么下面的解决方案不起作用?我想填充value按 排序的最后一个非空值idx。
我所看到的:
idx | coalesce
-----+----------
1 | 2
2 | 4
3 |
4 |
5 | 10
(5 rows)
Run Code Online (Sandbox Code Playgroud)
我想要的是:
idx | coalesce
-----+----------
1 | 2
2 | 4
3 | 4
4 | 4
5 | 10
(5 rows)
Run Code Online (Sandbox Code Playgroud)
代码:
with base as (
select 1 as idx
, 2 as value
union
select 2 as idx
, 4 as value
union
select 3 as idx
, null as value
union …Run Code Online (Sandbox Code Playgroud) c++ ×8
c++11 ×2
postgresql ×2
sql ×2
arrays ×1
const ×1
constants ×1
constructor ×1
containers ×1
csv ×1
decltype ×1
function ×1
ide ×1
max ×1
move ×1
null ×1
optimization ×1
performance ×1
pointers ×1
psql ×1
qt ×1
qt-creator ×1
reference ×1
return ×1
stdarray ×1
templates ×1
throw ×1
tree ×1
unique-ptr ×1
vector ×1
virtual ×1