草庐IT

base_type

全部标签

c++ - 前向声明的类型和 "non-class type as already been declared as a class type"

我对以下代码有疑问:templatevoidfoo(structbar&b);structbar{};intmain(){}它在GCC上编译成功,但在MSVC(2008)上编译失败并出现以下错误:C2990:“bar”:已声明为类类型的非类类型是代码错误还是MSVC中的错误?如果我在模板定义之前添加structbar;就可以了。 最佳答案 我们有我们的赢家:https://connect.microsoft.com/VisualStudio/feedback/details/668430/forward-declared-type-

c++ - 错误 C2678 : binary '=' : no operator found which takes a left-hand operand of type 'const Recipe' (or there is no acceptable conversion)

我正在尝试对每个元素中包含一个int和一个字符串的vector进行排序。它是一个称为vector食谱的类类型的vector。出现上述错误,这是我的代码:在我的Recipe.h文件中structRecipe{public:stringget_cname()const{returnchef_name;}private:intrecipe_id;stringchef_name;在我的Menu.cpp文件中voidMenu::show()const{sort(recipes.begin(),recipes.end(),Sort_by_cname());}在我的Menu.h文件中#include

c++ - std::is_convertible 用于 type_info

在C++11中,可以通过usingstd::is_convertible确定类型A的变量是否可以隐式转换为类型B.如果你真的知道类型A和B,这很有效,但我只有type_infos。所以我正在寻找的是这样的功能:boolmyIsConvertible(consttype_info&from,consttype_info&to);是否可以在C++中实现类似的东西?如果是,怎么办? 最佳答案 在可移植的C++中做你想做的事是不可能的。可能如果您将自己限制在给定的平台上,则有可能获得部分答案。例如那些遵守ItaniumABI的平台将实现此功

c++ - 调用 ~Derived() 和 ~Base() 之间的对象状态

问题C++标准对一个对象在时间上的状态有什么保证在派生类的析构函数执行之后,但在基类的析构函数执行之前?(此时派生类的子对象的析构函数被调用。)例子#includestructBase;structMember{Member(Base*b);~Member();Base*b_;};structBase{virtualvoidf(){}virtual~Base(){}};structDerived:Base{Derived():m(this){}virtual~Derived(){}virtualvoidf(){}std::strings;Memberm;};Member::Member

c++ - CRTP + 特征类 : "no type named..."

我尝试使用模板化类实现CRTP,但在使用以下示例代码时出现错误:#includetemplateclassTraits{public:typedeftypenameT::typetype;//'staticconstunsignedintm_const=T::m_const;staticconstunsignedintn_const=T::n_const;staticconstunsignedintsize_const=T::m_const*T::n_const;};templateclassCrtp{public:typedeftypenameTraits::typecrtp_typ

c++ - msvc 相当于 gcc 的 __BASE_FILE__

在VisualC++中是否有任何等效于__BASE_FILE__的东西?我想知道当前正在由VC++编译的文件的名称。注意:__FILE__展开为当前文件,例如它可能是#include之一。来自gcc的文档:__BASE_FILE__此宏以C字符串常量的形式扩展为主输入文件的名称。这是调用C编译器时指定为参数的源文件。 最佳答案 感谢John的评论,这是一个解决方法。如果您简单地输入__BASE_FILE__=%(Filename),它不会生成文字字符串。所以把它放在双引号之间;我还添加了扩展名,因为%(Filename)没有它。__

c++ - std::string 的 type_traits 段错误

从UsingSFINAEtocheckforglobaloperator收集信息和templates,decltypeandnon-classtypes,我得到了以下代码:http://ideone.com/sEQc87基本上,我将两个问题的代码结合起来,如果它有ostream声明,则调用print函数,否则调用to_string方法。摘自问题1namespacehas_insertion_operator_impl{typedefcharno;typedefcharyes[2];structany_t{templateany_t(Tconst&);};nooperatorstruct

使用JavaScript将base64String转换为可下载的文件

我想在单击链接时下载文件。untitled.pngJavaScript代码functiondownload(id,name,contenttype,filebyte){}看答案您可以使用此简单的下载功能,将其传递给您所需的URL,文件名和类型。functiondownload(url,filename,mimeType){return(fetch(url).then(function(res){returnres.arrayBuffer();}).then(function(buf){returnnewFile([buf],filename,{type:mimeType});}));}down

c++ - 对于具有默认分配器的标准容器,std::container::size_type 是否保证为 size_t?

喜欢:std::string::size_typestd::list::size_typestd::map::size_typestd::vector::size_type等等两者都是cplusplus.com和cppreference.com说他们通常是size_t,但它们是否真正、明确地保证为size_t的标准除非使用自定义分配器? 最佳答案 对于STL容器-不。[container.requirements.general]中标准的表96,其中列出了任何容器的容器要求X,解释得很清楚:但是,对于basic_string,siz

c++ - 获取错误 : 'mutex' in namespace 'std' does not name a type in MinGW mysys prompt

我已经从官方网站下载了MinGW并将其安装在我的Windows8.1机器上。运行g++--version给我g++.exe(GCC)4.8.1。我正在尝试在MinGW编译器中编译现有的代码库,但它因以下错误而失败:error:'mutex'innamespace'std'doesnotnameatypeprivate:std::mutexm_Mutex;^error:'condition_variable'innamespace's还有更多与锁定和线程相关的错误。!我能够在Cygwin-64中编译相同的代码库,没有任何问题。我需要在MinGW中成功构建和编译,以便创建一些与MSVS兼容