草庐IT

output_type

全部标签

c++ - boost::单位::数量 "incomplete type"错误

我正在尝试在项目中使用boost::units但遇到了麻烦。我有一个模板类,其中有一些quantity对象作为成员。在一个中,我希望存储一个具有压力维度的值,所以我有quantitypress;声明为成员变量。然而,这给出了一个错误,指出quantity需要两个模板参数(源代码显示第二个模板参数应该默认为double)。如果我然后指定quantitypress;相反,我得到一个错误,上面写着错误:字段“press”的类型不完整。是我做错了什么还是压力的执行有问题?最小示例:#include#includeusingnamespaceboost::units;usingnamespace

c++ - 未找到 : FeedInputs: unable to find feed output TensorFlow

我在本网站尝试使用C++中的Tensorflow保存模型的示例:https://medium.com/jim-fleming/loading-a-tensorflow-graph-with-the-c-api-4caaff88463f#.ji310n4zo效果很好。但它不保存变量a和b的值,因为它只保存图形而不保存变量.我试图替换以下行:tf.train.write_graph(sess.graph_def,'models/','graph.pb',as_text=False)与saver.save(sess,'models/graph',global_step=0)当然是在创建保护程

c++ - 保证 std::container::size_type 是一个 std::size_t

正在关注thisquestion,我决定使用std::size_t作为size_type对于每个容器,出于明显的可读性原因。我知道这在理论上是可能的std::container::size_type不是std::size_t,但我认为我当前和future的配置并非如此。但是,为了避免恶意错误,我在使用它们时会检查类型是否相同。例如:BOOST_STATIC_ASSERT(boost::is_same::size_type,std::size_t>::value);std::vectorx;/*fillx*/for(std::size_ti=0;i代码的另一个地方,我使用了一个std::

C++, Linux : error: conversion from ‘boost::unique_future<void>’ to non-scalar type ‘boost::shared_future<void>’ requested. 如何绕过它?

我尝试使用boostthreadfutures.所以如图here我们可以得到sharedfuture来自packagedtask.所以我在linux上尝试这样的功能:templatevoidpool_item(boost::shared_ptr>pt){boost::shared_futurefi=pt->get_future();//error//...但调用它时出错:../../src/cf-util/thread_pool.h:Inmemberfunction‘voidthread_pool::pool_item(boost::shared_ptr>)[withtask_retu

C++11 : How can I define a function that accept a universal reference of a specific type of object?

问题:我正在用C++11开发一个程序。我想编写一个接受右值引用和左值引用的函数。(即通用引用)。以下函数接受通用引用参数:templatevoidfunction(T&&t){/*SNIP*/}但是,它接受所有类型的参数。它破坏了函数的类型安全。想让它接受特定类型的参数怎么办?这是我能想到的解决方案:voidfunction(Class&t){/*SNIP*/}voidfunction(Class&&t){function(t);}然而,它很丑陋。如果我想更改要接受的参数或更改函数名称,我必须更新函数的两个版本。有比这更好的等价物吗?编辑:问题已解决。你们都回答得很好。我对两个答案都投

C++ 错误 : "Expression must have integral or enum type"

这个问题在这里已经有了答案:Whycan'ttheswitchstatementbeappliedtostrings?(22个答案)关闭8年前。我在下面的(不完整的)函数的switch语句中收到错误“表达式必须具有整数或枚举类型”。我盯着它看了一会儿,想不通这是怎么回事。非常感谢任何见解。std::stringCWDriver::eval_input(std::stringexpr){std::vectorparams(split_string(expr,""));std::stringoutput("");if(params.size()==0){output="Inputcanno

c++ - has_type 模板为 struct type {} 返回 true;

有很多方法可以实现has_type推导ifT的模板有一个名为type的嵌套类或typedef.即namespacedetail{templatestructtovoid{typedefvoidtype;};}templatestructhas_type:std::false_type{};//thisonewillonlybeselectedifC::typeisvalidtemplatestructhas_type::type>:std::true_type{};或者templatechartest_for_type(...){return'0';}templatedoubletes

c++ - 如何表达 "the minimum integral type larger than T"?

假设我有一个整数类型T(有符号或无符号)。我想(在编译时)引用可以容纳的最小整数类型(有符号或无符号),比如说std::numeric_limits::max()加1(在非溢出意义上,我的意思是)。这样做的通用方法是什么? 最佳答案 对于无符号类型,这可以解决问题:templateconstexprunsignedsize_in_bits(){returnsizeof(T)*CHAR_BIT;}templateusingleast_larger_uint_t=typenameboost::uint_t()+1>::least;如果我

c++ - 警告 C4673 : throwing 'ex::traced_error<EX>' the following types will not be considered at the catch site

MSVC10和MSVC9在编译我的异常框架时都生成了4级警告消息,尽管程序的行为似乎是正确的。异常框架相当庞大和复杂,但我已经设法将其归结为它的本质。这是一个完整的程序,您可以在VS10中编译和运行#include#include#include#include#includeusingnamespacestd;namespaceex{classgeneric_error:virtualpublicstd::exception{public:generic_error(intthread_id):thread_id_(thread_id){}constchar*what()constt

c++ - 在具有模板构造函数 : weird incomplete type issue 的类中使用智能指针的 Pimpl

当使用带有pImpl习惯用法的智能指针时,如structFoo{private:structImpl;boost::scoped_ptrpImpl;};明显的问题是Foo::Impl在生成Foo的析构函数时不完整。编译器通常会在那里发出警告,而Boost智能指针内部使用的boost::checked_delete静态断言类Foo::Impl已完成如果不是这种情况,则触发错误。要编译上面的例子,必须这样写structFoo{~Foo();private:structImpl;boost::scoped_ptrpImpl;};并在实现文件中实现一个空的Foo::~Foo,其中Foo::Im