草庐IT

is_const_method

全部标签

c++ - std::is_class 的实现

我想知道std::is_class(http://www.cplusplus.com/reference/type_traits/is_class/)是如何实际实现的。我查看了/usr/include/c++/4.8/tr1/type_traits但似乎唯一存在的是:///is_classtemplatestructis_class:publicintegral_constant{};__is_class的定义在任何地方都找不到(或者我只是看得不够深入)。无论如何,如果有人能指出我在哪里寻找这个(以及std命名空间中的其他is_***),我会很高兴 最佳答案

c++ - 对 'cv::viz::Viz3d::Viz3d(std::string&const)' 的 undefined reference

我已经使用qtcreator运行了我的opencv代码,当我尝试使用Viz库时得到了这个答案。代码:#include#include#include#include#include///Createawindowviz::Viz3dmyWindow("VizDemo");///StarteventloopmyWindow.spin();///Eventloopisoverwhenpressedq,Q,e,Eprintf("Firsteventloopisover\n");///Accesswindowviaitsnameviz::Viz3dsameWindow=viz::getWind

c++ - 在 Visual Studio 中构建解决方案时出现 "Unable to create directory"错误 "Access to path is denied."

我正在尝试在VS2013中构建一个VS2010C++项目(准确地说,是来自SteinbergVstSDK的示例项目)并出现以下错误:C:\ProgramFiles(x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.CppBuild.targets(1235,5):errorMSB3191:Unabletocreatedirectory"C:\ProgramFiles(x86)\CommonFiles\VST3\Steinberg".Accesstothepath'C:\ProgramFiles(x86)\CommonFiles\VST3\St

c++ - 按值或 const 引用传递函数?

我应该按值还是按对一个函数的引用来传递std::string。此函数将此值存储在类的成员变量中。当谈到值传递或引用传递时,我总是感到困惑。请消除我对此的困惑。代码如下:classDataStore{public:voidaddFile(conststring&filename,constset&filePaths){if(dataStoreMap.insert(make_pair(filename,filePaths)).second){cout>dataStoreMap;};我应该像这样声明函数吗:voidaddFile(conststring&filename,constset&f

c++ - 为什么 const 类成员必须是静态的才能得到适当的优化?

给定:classFoo{constintx=5;public:inlineintget(){returnx;}};classBar{staticconstintx=5;public:inlineintget(){returnx;}};intfn0(Foo&f){returnf.get();}intfn1(Bar&b){returnb.get();}编译后的输出提供内存获取以读取fn0()中x的值,而添加static结果是文字5被内联到fn1()中。这意味着只有当整数常量为静态时,get()的调用方才可以像使用常量代替get()一样进行优化。我有更复杂的情况,其中static不合适。派生

c++ - 允许这种派生到基础转换的理由是什么(当它似乎违反 IS-A 时)?

我用来快速确定派生到基础的转换是否合法的规则是检查在转换的上下文中,derived是否是一个base(即,derived提供对base的公共(public)API的访问)。它在C++Primer(第5版)中更好地表述为:Foranygivenpointinyourcode,ifapublicmemberofthebaseclasswouldbeaccessible,thenthederived-to-baseconversionisalsoaccessible,andnototherwise.现在让我们想象一个类层次结构如下:classBase{public:intmem;};clas

c++ - 自动转换模板<T>到模板<const T>

下面的这段应该主要用于T={char,constchar}的字符串View是主要的预期模板实例化目标。cmp函数应该类似于strcmp来比较View。.问题是虽然char*愉快地转换为constchar*我不知道如何获得SVec转换为SVec一样开心。最后一行(cout)无法编译。我必须明确地进行转换(cmp(SVec(rv),rvc))。它可以像char*一样自动吗?至constchar*?代码(大大简化):templateclassSVec{protected:T*begin_;size_tsize_;public:SVec(T*begin,size_tsize):begin_(b

c++ - 为什么 static const char * template struct 成员没有初始化

我有一些C++11模板代码,我正在尝试移植到VisualC++Compiler2015。原始代码工作得很好,但是我需要重写它以解决constexpr的问题。Theoriginalcode(simplifiedexample)#includestructString{staticconstexprconstchar*value{"STRING"};};templateclassDerived{public:staticconstexprconstchar*value{Base::value};};templatestructFoo{staticconstexprconstchar*val

c++ - 类型的模板特化和 const 限定符

为什么编译器期望模板在(具体)类型上单独特化T和constT?让我举个例子。我有一个由类类型键控的无序映射Keystd::unordered_mapdata;要编译它必须专门化std::hash在类型上Key作为namespacestd{templateclasshash{/*implementation*/};}但是,当我将map类型更改为std::unordered_mapdata;编译器没有使用我的特化,而是选择了通用的std::hash,这只不过是一个编译时断言,直到我专门化std::hash.撇开使用const限定映射键类型的实用程序,为什么不constT折叠到T在寻找这种情

c++ - 期望 const std::string & 的函数的链接器错误

尝试链接共享库(gtkmm)时,我收到其签名包含std::stringconst&的函数的链接器错误。例如,如果函数声明为voidset_icon_from_file(conststd::string&);g++报告undefinedreferenceto`Gtk::Window::set_icon_from_file(std::stringconst&)'我正在使用pkg-config中的链接器标志,而其他函数(例如,将基本类型作为参数的函数)不会发生这种情况,因此我怀疑链接器配置正确。readelf我的目标文件给了我45:00000000000000000NOTYPEGLOBALD