小编Kir*_*xas的帖子

std::bind 和 boost::bind 多态性之间的区别

我有一个派生类,从中绑定了一个我没有在此类中重写的虚函数,因此我希望调用父类中的一个。
它与 boost (1.55) 配合得很好,但如果我从 C++11 切换到 std::bind,它会拒绝使用

错误 C2100:非法间接寻址 1> 功能(1152):请参阅函数模板实例化 '_Rx std::_Pmf_wrap<_Pmf_t,_Rx,_Farg0,_V0_t,_V1_t,_V2_t,_V3_t,_V4_t,_V5_t,>::operator ()( _Wrapper &) const' 正在编译 1> with 1> [ 1> _Rx=bool, 1> _Pmf_t=bool (__thiscall Base::* )(void), 1> _Farg0=Base, 1> _V0_t=std::_Nil, 1> _V1_t=std::_Nil, 1> _V2_t=std::_Nil, 1> _V3_t=std::_Nil, 1> _V4_t=std::_Nil, 1> _V5_t=std::_Nil, 1> =std: :_Nil, 1> _Wrapper=派生 1> ]

这是最小代码

class Runnable { virtual bool Run() =0;};
class Base : public Runnable { bool Run() {/*do stuff*/ return true;}};
class Derived : public Base {};

Derived d;
std::function<bool()> …
Run Code Online (Sandbox Code Playgroud)

c++ boost-bind stdbind c++11 visual-studio-2012

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

如何在C++(Armadillo)中创建1:n的向量?

这么简单的问题,但我没有在犰狳的文件中找到答案.

我正在寻找与Matlab相当的Armadillo/C++,x = (1:n)其中n是一个数字,x因此是一个向量[1, 2, 3..., n-1, n].

c++ matlab armadillo

4
推荐指数
1
解决办法
1700
查看次数

使用 std::enable_if

我正在尝试使用 来专门针对一系列类型的函数std::enable_if
这是我想要完成的任务的一个更简单的版本。

#include <type_traits>
#include <string>

struct Ip
{};

template <typename T>
bool Equal(const std::string& s, const T& data)
{return s == data;}

template <typename T>
bool Equal(const std::string& s, const typename std::enable_if<std::is_integral<T>::value, T>::type& data)
{
    //int specific
}

template <typename T>
bool Equal(const std::string& s, const typename std::enable_if<std::is_floating_point<T>::value, T>::type& data)
{
    //Float specific
}

//Specialization
template <> bool Equal(const std::string& s, const Ip& data)
{
   //Ip specific
} 

int main()
{
    //Equal("21",21); // Do not compile …
Run Code Online (Sandbox Code Playgroud)

c++ templates enable-if c++11

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

VS 2010未检测到模板内代码的任何更改

我们假设我已经在头文件中编写了下一个代码

template<typename MyType> 
inline void function()
{
    /*some code here*/;
} 
Run Code Online (Sandbox Code Playgroud)

当我在Visual Studio 2010 SP1中按下构建解决方案时,它会构建代码,然后我会得到下一个

========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ========== 
Run Code Online (Sandbox Code Playgroud)

似乎一切都很好,但是如果我在模板中添加任何代码(即使它是一个有错误的代码),VS也不会检测到更改并告诉构建成功.例如:

template<typename MyType> 
inline void function()
{
    this is a plane text so, compiler should give an error //line with error
    /*some code here*/;
} 
Run Code Online (Sandbox Code Playgroud)

构建结果:

 ========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ========== 
Run Code Online (Sandbox Code Playgroud)

如果我在模板外添加任何错误代码,VS会告诉我构建FAILED,之后它实际上会找到模板外部和内部的所有错误.强制VS检测模板内部任何更改的另一种方法是重建整个项目,但在我的情况下需要花费太多时间,所以我想找到一些其他方法来强制VS检测我的代码中的更改?任何人都可以建议为什么会出现这种情况以及如何克服它?

c++ visual-studio-2010

0
推荐指数
1
解决办法
35
查看次数