小编use*_*336的帖子

Constexpr重载模板函数的别名

尝试在特定类类型上为该类的特定构造函数设置make_shared别名.我最好的尝试:

class foo { public: foo(int x) : y(x) {} int y; };
constexpr auto newfoo = static_cast<std::shared_ptr<foo>(*)(int)>(std::make_shared<foo>);
Run Code Online (Sandbox Code Playgroud)

产量:

error: invalid static_cast from type ‘<unresolved overloaded function type>’ to type ‘std::shared_ptr<foo> (*)(int)’
constexpr auto newfoo = static_cast<std::shared_ptr<foo>(*)(int)>(std::make_shared<foo>);
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

c++ templates constexpr

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

非const调用const成员函数失败,只读位置C++

这篇文章后,我实现了一个类似的访问器

template<class T> class qv {
  virtual const T& operator[](int i) const = 0;
  T& operator[](int i) { return const_cast<T&>(static_cast<const qv*>(this)->operator[](i)); }
};
template<class T> class qq : public qv<T> {
 public:
  const T& operator[](int i) const override { return this->data[i]; }
 protected:
  T data[5];
};
Run Code Online (Sandbox Code Playgroud)

assignment of read-only location在尝试做类似的事情时得到一个:

int main(int argc, char** argv) {
  qq<int> q;
  q[3] = 2; // read-only location compile error, g++ 6.3
}
Run Code Online (Sandbox Code Playgroud)

这是导致问题的继承,但我不知道是什么或为什么.顺便说一下,如果我使用静态或const_cast作为上面的内部演员是否重要?

c++ const

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

在 JUnit 或其他 Java 包中使用 Expect 与 Assert

我是一个 C++-er 做一些 Java。在 C++ 广泛使用的gtest包中,Expectations 和 Assertions 之间存在区别:

 EXPECT_EQ(4, 2); // will ultimately cause test failure but test continues to run
 ASSERT_EQ(4, 2); // test will stop here and fail
Run Code Online (Sandbox Code Playgroud)

如果测试失败,断言将停止测试。期望不会停止测试。如果未满足预期,则测试将失败。不同之处在于,我们可以在一次测试运行中看到代码块中有多少未满足预期。

这在 Java 中有等价的吗?我目前正在使用 JUnit,并且看到到处都在使用断言:

Assert.assertEquals(4, 2); // just like C++, this stops the show
Run Code Online (Sandbox Code Playgroud)

这很好,但问题是你看不到在一次测试运行中有多少失败!!

java junit

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

Boost 1.53.0 - LNK1104构建VC++ 11时出错

我试图第一次构建boost v.1.53并收到此错误消息:

错误1错误LNK1104:无法打开文件'libboost_date_time-vc110-mt-gd-1_53.lib'C:\ Users\ryant_000\documents\visual studio 2012\Projects\Phase 2\Phase 2\LINK Phase 2

在我的include目录中有C:....\boost_1_53_0,在链接器菜单上有我的附加依赖项C:...\boost_1_53_0\stage\lib.

我错过了什么文件链接,我在搜索文档后找不到它?

非常感谢.

c++ linker boost visual-studio-2012

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

为什么Rich Hickey认为虚拟机而不是操作系统是未来的平台?

关于为何选择Clojure?Rich Hickey(假设)声称"虚拟机,而不是操作系统,是未来的平台"引用类型系统,抽象操作系统的库,内存管理和字节码+ JIT编译.我理解所有这些东西都带有VM平台,但它们已经存在了25年.什么将使操作系统和硬件抽象在未来更加可取,特别是在权衡这种抽象的性能成本时?

jvm clojure

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

“TypeError:Person() 采用 1 个位置参数,但给出了 2 个”,但构造函数采用两个参数

这是最奇怪的事情。我的 python 刚刚停止处理其构造函数中具有多个参数的类?运行 python 3.8.10 出现错误TypeError: Person() takes 1 positional argument but 2 were given

def Person(object):
    def __init__(self, a, b):
        self.aa = a
        self.bb = b

pp = Person(20, 40)
Run Code Online (Sandbox Code Playgroud)

如果我将 Person__init__降低到一个参数,那么它就会起作用。如果我将其提高到 3,则会出现相同的takes 1 but 3 were given错误。我完全被难住了?

python

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

标签 统计

c++ ×3

boost ×1

clojure ×1

const ×1

constexpr ×1

java ×1

junit ×1

jvm ×1

linker ×1

python ×1

templates ×1

visual-studio-2012 ×1