小编Agr*_*hak的帖子

QtCreator:找不到有效的工具包

仅安装在Windows 7上的IDE.我想创建一个Plain C++项目(非QT项目); 但是我收到一个错误:找不到有效的工具包.当我点击选项 - >套件时,我看到桌面(默认)套件,它没有显示任何错误.

我收到错误是因为我没有安装Qt库吗?如果是这样,有什么办法可以绕过下载/安装并只使用IDE?

c++ ide qt qt-creator

64
推荐指数
5
解决办法
13万
查看次数

常量指针的向量?

以下不编译(非常详细的错误,但基本上"不能重载"和"从'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)

c++ pointers const vector

7
推荐指数
2
解决办法
9981
查看次数

派生类调用时的虚函数性能?

从编译时已知为派生类的类调用虚方法时是否存在性能损失?下面我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)

c++ performance virtual function derived-class

6
推荐指数
1
解决办法
404
查看次数

将psql输出保存到csv文件

我有一个查询写在位于/ 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)

sql csv postgresql psql postgresql-copy

6
推荐指数
1
解决办法
1945
查看次数

使用模板参数进行Decltype

test1.cpp下面编译,但test2.cpp不编译.两者之间的唯一区别是我Handle::add_ittest1.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++ templates decltype c++11

6
推荐指数
1
解决办法
1143
查看次数

C++ throw()优化

根据优化C++,

对于您确定永远不会抛出异常的函数,使用空的异常规范(即,对声明追加throw()).

如果我知道90%的方法都不会抛出异常怎么办?将throw()附加到所有这些方法似乎是非常规和冗长的.如果没有,有什么好处?或者我在这里误解了什么?

c++ optimization throw

5
推荐指数
2
解决办法
710
查看次数

将 unique_ptr 的容器传递给构造函数?

我在这里缺少什么?为什么我不能将向量作为类构造函数的一部分移动?从构造函数中删除 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)

c++ containers constructor move unique-ptr

5
推荐指数
1
解决办法
3043
查看次数

使用std :: array创建树

底部的代码生成以下编译时错误.如果我使用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)

c++ arrays tree c++11 stdarray

5
推荐指数
1
解决办法
581
查看次数

为什么 std::max 由 const&amp; 返回?

我想找到最大值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)

c++ return reference constants max

5
推荐指数
1
解决办法
657
查看次数

PostgreSQL Last_value 忽略空值

我知道已经有人问过这个问题,但为什么下面的解决方案不起作用?我想填充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)

sql postgresql null window-functions

5
推荐指数
3
解决办法
6805
查看次数