小编Jam*_*lis的帖子

g ++的-g选项等同于VS2010 cl编译器?

使用带有-g选项的 g ++ ,我可以使用gdb进行调试.

与Visual Studio 2010 cl.exe编译器相同的是什么?

页面具有用于链接的不同库(调试/发布).

如果我使用cl.exe编译调试选项,是否必须使用相应的库链接选项(/ MD/MT vs/MDd/MTd)?

debugging compiler-options visual-studio visual-c++ visual-c++-2010

19
推荐指数
2
解决办法
8672
查看次数

为什么enable_shared_from_this有一个非虚拟析构函数?

我有一个宠物项目,我用它来试验C++ 11的新功能.虽然我有C的经验,但我对C++还不熟悉.为了训练自己进入最佳实践,(除了阅读很多),我已经启用了一些严格的编译器参数(使用GCC 4.4.1):

-std=c++0x -Werror -Wall -Winline -Weffc++ -pedantic-errors
Run Code Online (Sandbox Code Playgroud)

这对我来说很好.到现在为止,我已经能够解决所有障碍.但是,我有需要enable_shared_from_this,这给我带来了问题.编译我的代码时可能会收到以下警告(在我的情况下是错误的)(可能由触发器引发-Weffc++):

base class ‘class std::enable_shared_from_this<Package>’ has a non-virtual destructor
Run Code Online (Sandbox Code Playgroud)

所以基本上,我对这个实现有点疑虑enable_shared_from_this,因为:

  • 这是一个类的析构函数预期为子类应该始终是虚拟的,恕我直言.
  • 析构函数是空的,为什么要它呢?
  • 我无法想象有人会想通过引用删除他们的实例enable_shared_from_this.

但我正在寻找解决这个问题的方法,所以我的问题是,是否有正确的方法来解决这个问题?并且:我认为这个析构函数是假的,或者它有真正的目的吗?

c++ gcc boost shared-ptr c++11

18
推荐指数
2
解决办法
4420
查看次数

查看STL容器中的下一个元素

是否有可能在迭代器当前指向的容器中查看下一个元素而不更改迭代器?

例如在std :: set中,

int myArray[]= {1,2,3,4};
set <int> mySet(myArray, myArray+4);
set <int>::iterator iter = mySet.begin();

//peek the next element in set without changing iterator.

mySet.erase(iter); //erase the element if next element is n+1
Run Code Online (Sandbox Code Playgroud)

c++ iterator stl

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

我可以在不使用虚函数的情况下获得多态行为吗?

由于我的设备,我无法使用虚拟功能.假设我有:

class Base
{
    void doSomething() { }
};

class Derived : public Base
{
    void doSomething() { }
};

// in any place
{
    Base *obj = new Derived;
    obj->doSomething();
}
Run Code Online (Sandbox Code Playgroud)

obj->doSomething()将调用只是Base::doSomething()

有没有一种方法Base *obj,来调用doSomethingDerived

我知道我可以只是把virtual之前doSomething()Base它解决的问题,但我通过我的设备的限制,编译器不支持它.

c++ polymorphism virtual overriding function

18
推荐指数
4
解决办法
6944
查看次数

C++ 11 for循环是否允许新的或更好的优化?

在C++ 11中,我们现在可以:

void dosomething( std::vector<Thing>& things )
{
    for( Thing& thing : things )
    {
        dofoo( thing );
        wiizzz( thing );
        tadaa( thing );
    }

}
Run Code Online (Sandbox Code Playgroud)

我知道lambda的添加和使用是语法糖,但它提供了有趣的优化机会.

for循环怎么样?它只是语法糖还是编译器可以优化某些情况,它不能或者用手写循环太难了?

c++ optimization for-loop c++11

18
推荐指数
2
解决办法
1277
查看次数

使用c - printf将ieee 754 float转换为hex

理想情况下,以下代码将采用IEEE 754表示形式的浮点数并将其转换为十六进制

void convert() //gets the float input from user and turns it into hexadecimal
{
    float f;
    printf("Enter float: ");
    scanf("%f", &f);
    printf("hex is %x", f);
}
Run Code Online (Sandbox Code Playgroud)

我不太确定会出现什么问题.它将数字转换为十六进制数,但却是一个非常错误的数字.

123.1443 gives 40000000
43.3     gives 60000000
8        gives 0
Run Code Online (Sandbox Code Playgroud)

所以它正在做某事,我只是不太确定是什么.

帮助将不胜感激

c floating-point ieee-754

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

SSL是半对称的还是半不对称的?

我正在阅读http://www.definityhealth.com/marketing/how_ssl_works.html

看起来SSL使用非对称算法来交换对称密钥,之后它使用对称算法来加密数据.

有一个问题,我可以只使用非对称算法吗?就像Alice和Bob都有证书一样,他们都使用peer的公钥来加密数据.

ssl cryptography

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

为什么C#不能自动提供对C++/CLI事件的线程安全访问?

EventHandler委托的MSDN文档:

与C#和Visual Basic示例相比,Visual C++示例代码不要求您创建线程安全的临时变量.Visual C++版本自动提供线程安全访问,使您可以直接引发事件.

为什么C#不能自动提供对C++/CLI事件的线程安全访问?

.net c# c++-cli

17
推荐指数
1
解决办法
925
查看次数

如何并行构建多个配置?

我有一个带有12个解决方案配置的Visual Studio 2012解决方案.每个解决方案配置都是独立的(即,每个配置的输出完全不相关).

问题: 如何在一个步骤中构建所有12个配置,即在命令行上运行单个MSBuild命令,以及如何获得并行构建的配置?

例如,如果只有两个配置,Release/AnyCPU和Debug/AnyCPU,我希望这两个配置同时并行构建.

为了完整起见,以下是我的尝试; 我还没有解决这个问题的方法.


为了一次构建所有项目,我创建了一个带有Build目标的新项目文件,该目标在每个配置的Solution文件上运行MSBuild任务:

<Target Name="Build">
  <MSBuild Projects="cxxreflect.sln" Properties="SolutionDir=$(MSBuildProjectDirectory)\;Configuration=Release;Platform=Win32"     Targets="$(BuildCommand)" />
  <MSBuild Projects="cxxreflect.sln" Properties="SolutionDir=$(MSBuildProjectDirectory)\;Configuration=Release;Platform=x64"       Targets="$(BuildCommand)" />
  <MSBuild Projects="cxxreflect.sln" Properties="SolutionDir=$(MSBuildProjectDirectory)\;Configuration=Release;Platform=ARM"       Targets="$(BuildCommand)" />
  <MSBuild Projects="cxxreflect.sln" Properties="SolutionDir=$(MSBuildProjectDirectory)\;Configuration=Release(ZW);Platform=Win32" Targets="$(BuildCommand)" />
  <MSBuild Projects="cxxreflect.sln" Properties="SolutionDir=$(MSBuildProjectDirectory)\;Configuration=Release(ZW);Platform=x64"   Targets="$(BuildCommand)" />
  <MSBuild Projects="cxxreflect.sln" Properties="SolutionDir=$(MSBuildProjectDirectory)\;Configuration=Release(ZW);Platform=ARM"   Targets="$(BuildCommand)" />

  <MSBuild Projects="cxxreflect.sln" Properties="SolutionDir=$(MSBuildProjectDirectory)\;Configuration=Debug;Platform=Win32"       Targets="$(BuildCommand)" />
  <MSBuild Projects="cxxreflect.sln" Properties="SolutionDir=$(MSBuildProjectDirectory)\;Configuration=Debug;Platform=x64"         Targets="$(BuildCommand)" />
  <MSBuild Projects="cxxreflect.sln" Properties="SolutionDir=$(MSBuildProjectDirectory)\;Configuration=Debug;Platform=ARM"         Targets="$(BuildCommand)" />
  <MSBuild Projects="cxxreflect.sln" Properties="SolutionDir=$(MSBuildProjectDirectory)\;Configuration=Debug(ZW);Platform=Win32"   Targets="$(BuildCommand)" />
  <MSBuild Projects="cxxreflect.sln" Properties="SolutionDir=$(MSBuildProjectDirectory)\;Configuration=Debug(ZW);Platform=x64"     Targets="$(BuildCommand)" />
  <MSBuild Projects="cxxreflect.sln" Properties="SolutionDir=$(MSBuildProjectDirectory)\;Configuration=Debug(ZW);Platform=ARM"     Targets="$(BuildCommand)" />
</Target>
Run Code Online (Sandbox Code Playgroud)

这很好用,除了按顺序调用每个MSBuild任务,因此没有并行性(是的,每个配置构建都存在并行性,但我真的希望在配置构建中获得并行性).

为了使配置并行构建,我尝试使用MSBuild任务的BuildInParallel属性.我编写了一个预构建任务,为每个配置生成项目文件,然后尝试并行构建所有这些生成的项目:

<Target Name="PreBuild" Outputs="%(ProjectConfiguration.Identity)" Returns="%(BuildProject.Identity)"> …
Run Code Online (Sandbox Code Playgroud)

msbuild

17
推荐指数
1
解决办法
7516
查看次数

代码分析说'wWinMain'的注释不一致:这个实例没有注释

我正在写一些简单的win32内容,我正在使用以下wWinMain

int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow)
Run Code Online (Sandbox Code Playgroud)

VS2012快递代码分析说

C28251函数的注释不一致:此实例有一个错误'wWinMain'的不一致注释:此实例没有注释.请参阅c:\ program files(x86)\ windows kits\8.0\include\um\winbase.h(2201).LeesSpaceShip main.cpp 6

我不清楚注释是什么.那么什么是注释?哪些部分在我的代码中出错?

谢谢.

编辑:是的,代码编译并运行得很好.

c++ winapi annotations visual-c++

17
推荐指数
1
解决办法
8359
查看次数