小编Kar*_*rlM的帖子

writeln()或writefln()?

Hello World for D看起来像这样:

import std.stdio;

void main(string[] args)
{
    writeln("Hello World, Reloaded");
}
Run Code Online (Sandbox Code Playgroud)

来自http://www.digitalmars.com/d/

但是当我用gdc-4.4.5编译它时,我得到:

hello.d:5: Error: undefined identifier writeln, did you mean function writefln?
hello.d:5: Error: function expected before (), not __error of type _error_
Run Code Online (Sandbox Code Playgroud)

这是D1/D2的东西吗?图书馆的东西?看来,writefln是一个stdio库函数,而writeln则不是.

d

7
推荐指数
2
解决办法
2305
查看次数

Junit:在多个测试类中使用相同的测试对象

我有多个单独的测试类,它们都使用相同的测试对象。目前我在每个类中都使用 @Before,这显然不是一个很好的解决方案。

当然,一种选择是从创建此对象的抽象类继承。正如此处所述,这也不是一个好主意。

另一种选择是外部资源,但正如名称所说,用于资源而不是测试对象。

我觉得我错过了一些东西,因为这必须是 JUnit 中的一项基本任务。

java junit

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

使用std :: get <index>访问std :: variant

如何使用v.index()then 访问变体成员std::get<index>(v)

当变体具有多个相同类型的条目时很有用.

以下不起作用.此代码不能在GCC或clang上编译

#include <iostream>
#include <variant>
#include <string>
#include <sstream>

typedef std::variant<int, int, std::string> foo;

std::string bar(const foo f) {

    const std::size_t fi = f.index();
    auto ff = std::get<fi>(f);

    std::ostringstream ss;      
    ss << "Index:" << fi << "   Value: " << ff;
    return ss.str();
}


int main()
{
    foo f( 0 );

    std::cout << bar(f);
}
Run Code Online (Sandbox Code Playgroud)

当然有很多版本的std :: get,所以错误信息很冗长.

gcc抱怨(对于每个版本的get <>)

prog.cc:10:29: error: the value of 'fi' is not usable in a constant expression …
Run Code Online (Sandbox Code Playgroud)

c++ std variant c++17

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

标签 统计

c++ ×1

c++17 ×1

d ×1

java ×1

junit ×1

std ×1

variant ×1