小编q09*_*987的帖子

C++ - 需要重新编译时

您有一个许多库依赖的类.您需要修改一个应用程序的类.以下哪些更改需要在构建应用程序之前重新编译所有库?

  • 添加一个构造函数
  • 添加数据成员
  • 将析构函数更改为虚拟
  • 将具有默认值的参数添加到现有成员函数

谢谢

c++

17
推荐指数
2
解决办法
9278
查看次数

17
推荐指数
3
解决办法
6521
查看次数

如何编写将崩溃并生成转储文件的示例代码?

我开始学习windbg并找到了这篇好文章 如何使用WinDbg来分析VC++应用程序的崩溃转储?

现在我想按照说明一步一步地做.这是问题所在:我需要编写一些可以立即崩溃的示例代码,并创建一些可以由windbg使用的转储文件.

怎么写这样的代码?

void Example4()
{
    int* i = NULL;
    *i = 80;
}
Run Code Online (Sandbox Code Playgroud)

上面的代码会立即崩溃; 但是,我不知道在哪里可以找到转储文件?

谢谢

c++ windbg visual-c++

16
推荐指数
1
解决办法
2万
查看次数

在这样的塔中寻找尽可能多的人

首先,让我们看看这个问题,

马戏团正在设计一个塔式例程,由站在彼此肩膀上的人组成.出于实际和美学的原因,每个人必须比他或她下面的人更短更轻.考虑到马戏团中每个人的身高和体重,写一种计算这种塔中最大可能人数的方法.

EXAMPLE:
Input:
        (ht, wt): (65, 100) (70, 150) (56, 90) (75, 190) (60, 95) (68, 110)
Output: The longest tower is length 6 and includes from top to bottom: 
        (56, 90) (60,95) (65,100) (68,110) (70,150) (75,190)
Run Code Online (Sandbox Code Playgroud)

但我不太明白解决方案如下:

本书提出的解决方案:

  • 步骤1.首先按高度对所有项目进行排序,然后按重量进行排序.这意味着如果所有高度都是唯一的,则项目将按其高度排序.如果高度相同,则物品将按其重量进行分类.示例:»»排序前:(60,100)(70,150)(56,90)(75,190)(60,95)(68,110).»分选后:(56,90),(60,95),(60,100),(68,110),(70,150),(75,190).
  • 步骤2.找到包含增加高度和增加权重的最长序列.为此,我们:

  • a)从
    序列的开头开始.目前,max_sequence为空.

  • b)如果对于下一个项目,
    高度和重量不大于前一个项目的高度和重量,我们
    将此项目标记为"不合格"

    c)如果找到的序列的项目多于"最大序列",则变为"最大序列".

  • d)之后,从"不合适的项目"重复搜索,
    直到我们到达
    原始序列的末尾.

    public class Question {
    ArrayList<HtWt> items;
    ArrayList<HtWt> lastFoundSeq;
    ArrayList<HtWt> maxSeq;
    
    
    / Returns longer sequence
    ArrayList<HtWt> seqWithMaxLength(ArrayList<HtWt> seq1, ArrayList<HtWt> seq2) {
        return seq1.size() > seq2.size() ? seq1 : seq2;
    } …
    Run Code Online (Sandbox Code Playgroud)

algorithm

15
推荐指数
1
解决办法
4933
查看次数

C++ - 我应该在初始化列表中调用基类默认构造函数吗?

class A : public B
{
  ...
}

// case I : explicitly call the base class default constructor
A::A() : B()
{
  ...
}

// case II : don't call the base class default constructor
A::A() // : B()
{
  ...
}
Run Code Online (Sandbox Code Playgroud)

案例II是否与案例I相同?

对我来说,我假设在案例II中没有调用base clasa B的默认构造函数.

谢谢

///更新///

class B
{
public:
    B()
    {
        cout << "B constructor" << endl;
    }
};

class A : public B
{
public:
    A()
    {
        cout << "A constructor" << endl;
    }
}; …
Run Code Online (Sandbox Code Playgroud)

c++ inheritance constructor

15
推荐指数
4
解决办法
2万
查看次数

zmq - 何时使用zmq_bind或zmq_connect

Refer to http://hintjens.wdfiles.com/local--files/main:files/cc1pe.pdf
Page 22 Chapter Divide and Conquer

                    Ventilator[PUSH]
        ___________________|____________________             
        |                  |                   |
[PULL]Worker[PUSH] [PULL]Worker[PUSH]  [PULL]Worker[PUSH]
        |__________________|___________________|             
                           |                   
                     [PULL]Sink

// taskvent.c
    //  Socket to send messages on
    void *context = zmq_ctx_new ();
    void *sender = zmq_socket (context, ZMQ_PUSH);
    zmq_bind (sender, "tcp://*:5557");

    //  Socket to send start of batch message on
    void *sink = zmq_socket (context, ZMQ_PUSH);
    zmq_connect (sink, "tcp://localhost:5558");

// taskwork.c
    //  Socket to receive messages on
    void *context = zmq_ctx_new ();
    void *receiver = zmq_socket (context, ZMQ_PULL);
    zmq_connect …
Run Code Online (Sandbox Code Playgroud)

zeromq

15
推荐指数
1
解决办法
6743
查看次数

boost :: shared_ptr :: shared_ptr(const boost :: shared_ptr&)'被隐式声明为已删除

#include <iostream>
#include <boost/shared_ptr.hpp>
#include <boost/make_shared.hpp>
using namespace std;

struct Node
{
    Node(int data, boost::shared_ptr<int> next = boost::make_shared<int>())
      : m_data(data), m_next(next) {}

    int m_data;
    boost::shared_ptr<int> m_next;    
};
Run Code Online (Sandbox Code Playgroud)

错误:http: //www.compileonline.com/compile_cpp11_online.php - 在线编译和执行C++ 11(GNU GCC版本4.7.2)

Compiling the source code....
$g++ -std=c++11 main.cpp -o demo -lm -pthread -lgmpxx -lgmp -lreadline 2>&1
main.cpp: In constructor 'Node::Node(int, boost::shared_ptr)':
main.cpp:9:34: error: use of deleted function 'boost::shared_ptr::shared_ptr(const boost::shared_ptr&)'
In file included from /usr/include/boost/shared_ptr.hpp:17:0,
from main.cpp:2:
/usr/include/boost/smart_ptr/shared_ptr.hpp:168:25: note: 'boost::shared_ptr::shared_ptr(const boost::shared_ptr&)' is implicitly declared as deleted …
Run Code Online (Sandbox Code Playgroud)

c++ boost c++11

15
推荐指数
1
解决办法
6052
查看次数

为什么[=]可以用来修改lambda中的成员变量?

http://coliru.stacked-crooked.com/a/29520ad225ced72d

#include <iostream>

struct S
{
    void f()
    {
        //auto f0 = []     { ++i; }; // error: 'this' was not captured for this lambda function

        auto f1 = [this] { ++i; };    
        auto f2 = [&]    { ++i; };
        auto f3 = [=]    { ++i; };
        f1();
        f2();
        f3();
    }

  int i = 10;  
};

int main()
{
    S s;
    std::cout << "Before " << s.i << std::endl;
    s.f();
    std::cout << "After " << s.i << std::endl;
}

Before …
Run Code Online (Sandbox Code Playgroud)

c++ lambda c++11 c++14

15
推荐指数
3
解决办法
1172
查看次数

如何使用抗锯齿在OpenGL中绘制平滑线?

我需要在OpenGL中绘制一条平滑的线,这就是我所做的:

glEnable( GL_LINE_SMOOTH );
glEnable( GL_POLYGON_SMOOTH );
glHint( GL_LINE_SMOOTH_HINT, GL_NICEST );
glHint( GL_POLYGON_SMOOTH_HINT, GL_NICEST );
glBegin( GL_LINE_STRIP );
    for( UINT uiPoint = 0; uiPoint < iNumPoints; ++uiPoint )
    {
        const Coord &Node = vecPoints[uiPoint];
        glVertex3f( Node.x, Node.y, Node.z );
    }
glEnd();
Run Code Online (Sandbox Code Playgroud)

我还能做什么?

opengl line antialiasing

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

在类中使用union

我看到一些代码如下:

class A 
{
private:
    union {
        B *rep;
        A *next;
    }; // no variables of this anonymous defined!

    void func()
    {
        A *p = new A;

        p->next = NULL; // why p has a member variable of 'next'?
    }
};
Run Code Online (Sandbox Code Playgroud)

我用VS2010编译了上面的代码没有任何错误.这是问题,

为什么p有成员变量'next'?

    union {
        B *rep;
        A *next;
    };
Run Code Online (Sandbox Code Playgroud)

据我所知,这是一个匿名联盟,甚至没有定义变量.我们如何才能像这样访问这个联合中的成员变量?

c++ class unions

12
推荐指数
2
解决办法
1万
查看次数