草庐IT

weakly-typed

全部标签

c++ - 错误 : has initializer but incomplete type

我遇到了问题:在使用结构时有初始化器但类型不完整:在hpp文件中:classA{private:structvideoDT;};在一个cpp文件中:structA::videoDT{videoDT(intb):a(b){}inta;};voidtest(){structvideoDTtest(1);}那么问题来了:错误:有初始化器但类型不完整提前致谢 最佳答案 我认为问题在于test()无法访问A的私有(private)类型。这为我编译:classA{private:friendvoidtest();structvideoDT;};

c++ - 错误消息 : 'value_type' : is not a member of

我不明白这个神秘的错误消息,但我得到了30个`'value_type':isnotamemberof'TextFileLineBuffer'`当我在VC++6中编译以下代码时,//***行未注释。当然,如果我把它注释掉,它编译得很好。我想我在过去的两个小时里尝试了各种尝试,但都没有成功。任何提示将不胜感激。#include#include#include#include#include#include//wrapperforastringlinestructTextLine{std::stringm_sLineContent;operatorstd::stringconst&()con

c++ - make_signed<unsigned long>::type 是 int?

我使用的是VisualStudio2010,下面的代码让我有些困惑:#includeautox=std::make_signed::type();x将是int类型,但我预计会很长。我知道VS10中的int和long都是4字节整数。但是即使一个signedlong装进一个int,int对我来说也不是unsignedlong对应的signedinteger类型。所以我的问题是:这是错误/技术错误还是标准规范允许这种结果? 最佳答案 C++1120.9.7.3[meta.trans.sign]描述了make_signed:IfTnames

c++ - 从 weak_ptr 泄漏原始指针的可移植 hack

我有一个由shared_ptr组成的对象结构,加上weak_ptr以避免循环。原始指针是不行的,因为boost::serialization在通过对象跟踪作为序列化时间进行反序列化时需要恢复共享指针和弱指针。对象生命周期模式很复杂(粒子模拟)但完全可以预测。每当我使用weak_ptr::lock()时,我确信指针仍然有效。通常,我使用lock().get(),因为我只需要在很短的时间内使用该对象。现在,lock().get()对性能有影响,因为它会增加共享计数(在lock()中),然后在不久之后减少它(临时shared_ptr被破坏)。这boost.develpost从2002年开始,

c++ - LNK1112 : module machine type 'x64' conflicts with target machine type 'X86' : Qt creator

我有一个在linux上运行的应用程序,我正试图将其导入到windows上。我已经设置了所有库并对.pro文件进行了更改。现在,当我尝试构建项目时出现此错误:error:LNK1112:modulemachinetype'x64'conflictswithtargetmachinetype'X86'我不确定是什么导致了这个问题。我正在使用32位Qtcreator。我知道有几个链接讨论了更改项目属性,但所有这些都与在VisualStudio中更改它们有关。我正在使用Qtcreator并通过QtUI运行项目。所以我不确定如果必须解决这个问题,必须通过Qt对项目属性进行哪些更改。

c++ - std::weak_ptr:锁或 shared_ptr 构造函数?

似乎有两种方法可以暂时获取weak_ptr指向的资源的所有权:使用lock()将weak_ptr传递给shared_ptr构造函数这两者都会产生一个shared_ptr,如果weak_ptr为空并且锁返回一个nullptrshared_ptr构造函数抛出异常。所以问题是:什么时候应该使用一个或另一个?是否有与此相关的一般准则或最佳做法? 最佳答案 复制自http://en.cppreference.com/w/cpp/memory/weak_ptr/lockBoththisfunctionandtheconstructorofstd

C++ 调试窗口显示“<incomplete type> for string variable

据我所知,我正在以一种相当正常的方式初始化一个字符串,当我调试时,我的IDE(CLion)中的变量窗口将其值显示为.我有一些简单的代码导致字符串变量Bob出现问题.#includeintmain(){std::stringBob="thisdoesn'tshowupinthevariableswindow";std::cout我不知道它有什么影响,但我会包含CMakeLists文件,它似乎是我可以使用的最简单的文件。cmake_minimum_required(VERSION3.8)project(testing123)set(CMAKE_CXX_FLAGS"${CMAKE_CXX_F

c++ - 迭代器模式 - 错误 C2679 : binary '<<' : no operator found which takes a right-hand operand of type 'std::string'

这个问题在这里已经有了答案:errorC2679:binary'(1个回答)关闭5年前。我正在尝试使用迭代器模式进行迭代和打印,但出现错误这里是错误:errorC2679:binary'couldbe'std::basic_ostream&std::operator>(std::basic_ostream&,constchar*)'这是错误的来源std::coutgetName();#ifndef_ROBOT1_#define_ROBOT1_namespaceguitars{namespaceComposite{namespaceInventoryParts{usingnamespac

如何正确地从函数(type_traits)提供向量

我如何返回std::vector由此operator+()?#include#include#include#include#includetemplatestructis_std_vector:std::false_type{};templatestructis_std_vector>:std::true_type{};templatestd::enable_if_t>::value>operator+(T&&vec1,T&&vec2){for(inti=0;i(vec2.at(i)));returnvec1;}intmain(){std::vectorvec1{1,2,3,4,5};std

c++ - 如何在 C++11 中将容器 std::array<type, size> 用于多维数组?

例如,包含三个整数的一维数组可以定义为std::arraymyarray或myarray[3].有没有像std::array这样的容器对于像myarray[3][3]这样的多维数组? 最佳答案 一个关键部分是确保{}初始化工作类似于std::array,并尽可能合理地让自己保持pod状。与std::array的兼容性也很重要,什么比std::array更兼容??所以我的解决方案从std::array中生成多维数组小号:templatestructmulti_array_helper{usingtype=T;};templateusi