小编rah*_*man的帖子

如何让GIT忽略我的更改

虽然标题似乎与之前的问题类似,但我无法找到解决我的简单案例的方法:

  • 我致力于我的分支'ABCD': git commit -a .....
  • 然后决定访问之前的提交所以: git checkout 2387687326487
  • 在这里,我做了一些更改,仅用于测试目的,我不想保留它们
  • 我完成了,我想回到我最近的提交(再次:忽略我对旧提交所做的更改):命令git checkout 'ABCD'给出错误:

您对以下文件的本地更改将被结帐时覆盖....请提交或存储...

虽然我不想承诺或藏匿或其他什么.我只想回家:)我该怎么办?

git

45
推荐指数
5
解决办法
8万
查看次数

Eclipse的最佳XML编辑器

我是XML的新手.请告诉我Eclipse最好的XML编辑器插件.我需要创建/编辑XML和XSD文件.

xml eclipse eclipse-plugin editor

36
推荐指数
1
解决办法
8万
查看次数

unique_ptr编译错误

如果我告诉你我无法编译,我想这很尴尬.你能帮帮我吗

#include<memory>
using namespace std;

int  main()
{
    std::unique_ptr<int> p1(new int(5));
    return 0;
}
Run Code Online (Sandbox Code Playgroud)
$ gcc main.cpp 
main.cpp: In function ‘int main()’:
main.cpp:6:2: error: ‘unique_ptr’ was not declared in this scope
main.cpp:6:13: error: expected primary-expression before ‘int’
main.cpp:6:13: error: expected ‘;’ before ‘int’

$ gcc --version
gcc (Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1
Run Code Online (Sandbox Code Playgroud)

c++ linux gcc stl unique-ptr

19
推荐指数
1
解决办法
3万
查看次数

如何用C++中的引用替换指针?

"我确信有几十个问题都有相同的标题.其中很多都是重复的.我的也可能是重复的,但我找不到任何问题.所以我试着让它变得非常简洁,简洁."

我有这样的层次结构:

class Shape {
public:
   virtual void virtualfunc()  { std::cout << "In shape\n"; }
};

class Circle: public Shape {
public:
   void virtualfunc()  { std::cout << "In Circle\n"; };
};
Run Code Online (Sandbox Code Playgroud)

当我在指针的帮助下使用类时,函数按照我的预期调用:

int main() {
   Shape shape_instance;
   Shape* ref_shape = &shape_instance ;
   Circle circle_instance;
   Circle* ref_circle = &circle_instance;

   ref_shape = dynamic_cast<Shape*> (ref_circle);
   ref_shape->virtualfunc();
}
Run Code Online (Sandbox Code Playgroud)

这里程序调用virtualfunc()派生类,结果自然是:In Circle

现在,我想摆脱指针,改为使用引用,并获得相同的结果.所以我做了一些微不足道的修改main(),看起来像这样:

int main() {
   Shape shape_instance;
   Shape& ref_shape = shape_instance;
   Circle circle_instance;
   Circle& ref_circle = circle_instance;

   ref_shape = dynamic_cast<Shape&>(ref_circle); …
Run Code Online (Sandbox Code Playgroud)

c++ pointers reference

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

如何测量std :: unordered_map的内存使用情况

我们知道基于哈希表的容器实现就像std::unordered_map使用了很多内存但我不知道多少是多少?

除了空间复杂性表示法,并且不考虑容器元素是否是指向更大对象的指针:

有没有办法弄清楚这样的容器在运行时使用了多少字节

有没有办法在运行时告诉任何容器使用多少内存?

c++ unordered-map

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

如何使用增强屏障

什么是提升:障碍,如何使用这种提升方法.你能给我一个明确的例子,因为我发现了以下例子:

    bool wait()
    {
        boost::mutex::scoped_lock lock(m_mutex);
        unsigned int gen = m_generation;

        if (--m_count == 0)
        {
            m_generation++;
            m_count = m_threshold;
            m_cond.notify_all();
            return true;
        }

        while (gen == m_generation)
            m_cond.wait(lock);
        return false;
    }
Run Code Online (Sandbox Code Playgroud)

在上面的代码中:m_cond.notify_all();是否进入其他等待线程?你能告诉我有关屏障功能的信息吗?谢谢.

c++ boost

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

如果在wait()之前调用notify()怎么办?

我有一种情况,可以在wait()之前调用notify()'.

当我通过向他发送消息通知他时,我正在尝试制作一个模拟器来安排下一个事件.所以我设计了一个wait-> notify-> scedule链

void Broker::pause()
{
    boost::unique_lock<boost::mutex> lock(m_pause_mutex);
    {
        std::cout << "pausing the simulation" << std::endl;
        m_cond_cnn.wait(lock);
        std::cout << "Simulation UNpaused" << std::endl;
        // the following line causes the current function to be called at 
        // a later time, and a notify() can happen before the current function
        // is called again
        Simulator::Schedule(MilliSeconds(xxx), &Broker::pause, this);
    }
}

void Broker::messageReceiveCallback(std::string message) {
    boost::unique_lock<boost::mutex> lock(m_pause_mutex);
    {
        m_cond_cnn.notify_one();
    }
}
Run Code Online (Sandbox Code Playgroud)

这里的问题是:可能存在在调用wait()之前调用notify()的情况.

这种情况有解决方案吗?谢谢

c++ synchronization boost condition-variable ns-3

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

字符串常量前的预期标识符

有这样的程序:

#include <iostream>
#include <string>
using namespace std;
class test
{
public:
    test(std::string s):str(s){};
private:
    std::string str;
};

class test1
{
public:
    test tst_("Hi");
};

int main()
{
    return 1;
}
Run Code Online (Sandbox Code Playgroud)

...为什么我执行时会得到以下内容

g ++ main.cpp

main.cpp:16:12: error: expected identifier before string constant
main.cpp:16:12: error: expected ‘,’ or ‘...’ before string constant
Run Code Online (Sandbox Code Playgroud)

c++ linux constructor

10
推荐指数
1
解决办法
3万
查看次数

函数指针生成'无效使用非静态成员函数'错误

我试图以更好的方式掌握指针功能概念.所以我有一个非常简单和有效的例子:

#include <iostream>

using namespace std;

int add(int first, int second)
{
    return first + second;
}

int subtract(int first, int second)
{
    return first - second;
}

int operation(int first, int second, int (*functocall)(int, int))
{
    return (*functocall)(first, second);
}

int main()
{
    int  a, b;
    int  (*plus)(int, int);
    int  (*minus)(int, int);
    plus = &add;
    minus = &subtract;
    a = operation(7, 5, add);
    b = operation(20, a, minus);
    cout << "a = " << a << " and b …
Run Code Online (Sandbox Code Playgroud)

c++ function-pointers

8
推荐指数
1
解决办法
3万
查看次数

Android MINA vs netty for Android

MINA和netty之间有一个非常丰富的比较,在这里 我想知道你的偏好,当平台是Android!

  • 我有一个主机应该接受连接以及建立与Android设备的连接.
  • 主机为其操作实现了Boost.ASIO.我需要为android端选择一个简单的框架.
  • 基于几个小时的谷歌搜索,我,相当新的java,缩小到MINAnetty.两者似乎都很好,虽然netty似乎更容易.
  • 当我读到一些关于在an​​droid中使用netty的bug报告时,我感到很困惑.

  • 连接到主机的Android模拟器的数量可以增长到很多.

所以问题很简单: 哪一个更好用:netty还是MINA?

BTW,还有其他建议的框架吗?

我非常重视你的意见和答案.谢谢

android apache-mina netty

7
推荐指数
1
解决办法
2469
查看次数