草庐IT

static-classes

全部标签

c++ - 将类型解析为 class::typedef 的更短方法

我有几个类(class)。现在它们被一个符号隔开。其中很少包含type(typedef),也很少没有。structA{...public:typedefsomeclasstype;}structB{...};我想实现一个SFINAE以这样的方式上课,Resolve::typeo1;//shouldresolveto'A::type'Resolve::typeo2;//shouldresolveto'B'一种方法是使用上一个链接中所示的基本SFINAE,它检查T是否包含type,然后使用bool检查器.例如,templatestructhas_type{typedefcharyes[3]

c++ - 警告 : base class ‘A’ should be explicitly initialized in the copy constructor

我有以下类结构:classA{A(){}A(constA&src){}};classB:virtualA{B():A(){}B(constB&src):A(src){}};classC:virtualA{C():A(){}C(constC&src):A(src){}};classD:virtualB,virtualC{D():B(),C(){}D(constD&src):B(src),C(src){}};这给了我警告:Incopyconstructor‘D’:warning:baseclass‘A’shouldbeexplicitlyinitializedinthecopyconstr

c++ - 错误 : Undefined symbols for architecture x86_64 with classes

我是一名初学者,正在编写一个帮助我节食的有趣程序。该程序尚未完成,但在我编写时正在编译。我不断收到标题中提到的错误:Undefinedsymbolsforarchitecturex86_64withclasses我看过类似的问题,但它们都与模板和继承类有关,这与我的情况不同。我只是在宣布一个类(class),没什么特别的。我认为这与未正确定义类有关,但我无法弄清楚它是什么。这可能是我想念的愚蠢的东西,但我仍然被困住了。谢谢。#include#includeusingnamespacestd;classMeal{private:stringname;intprotein;intcarbs

c++ - 窗体头文件中的 "error C2653: System is not a class or a namespace name",Visual C++

我之前关于同一项目的问题:one和two.没有必要阅读它们;只知道我正在尝试在VisualC++项目中使用nativeC++SDK。这比我最初想象的要棘手得多,但是这个网站关于ExtendinganativeC++projectwithmanagedcode已经帮助了我很多。按照最后一个链接的说明,我已将一个表单添加到我的nativeC++项目中,该项目已自动将项目转换为CLR项目。只有MainForm.cpp和Interface.cpp(允许nativeC++代码创建和显示MainForm的文件)使用/clr编译旗虽然;其他文件保持原样。我现在遇到的问题是,VisualStudio似

c++ - BOOST_STATIC_ASSERT_MSG - 缺少错误信息

我在让BOOST_STATIC_ASSERT_MSG发出有意义的错误消息时遇到问题。我把它归结为:#includenamespaceStaticChecks{BOOST_STATIC_ASSERT_MSG(false,"Whereismyerrormessage?");}指定的错误信息无处可见。相反,我得到以下信息:c:\tryit>x86_64-w64-mingw32-g++-O0-g-m64-Wall-IC:\boost_1_50_0-IC:\MinGW-W64\msys\includecompiletimechecks.cpp-c-ocompiletimechecks.cpp.o

C++ 错误 : a storage class can only be specified for objects and functions struct

我收到错误信息:错误:只能为对象和函数结构指定存储类在我的头文件中../**stud.h**Createdon:12.11.2013*Author:*///stud.h:DefinitionderDatenstrukturStud#ifndef_STUD_H#define_STUD_HstructStud{longmatrnr;charvorname[30];charname[30];chardatum[30];floatnote;};externStudmystud[];inteinlesen(structStud[]);voidbubbleSort(structStud[],int

c++ - 在方法/函数中使用 `static const std::string` 还是只使用 `const std::string` 更好?

我有一个方法/函数:voidfoo(){staticconststd::stringstrSQLQuery="SELECT...";//ormaybeconststd::stringstrSQLQuery="SELECT...";//someoperationsonstrSQLQuery//i.e.concatenatingwithWHERE,etc.:conststd::stringstrSQL=strSQLQuery+strWHERE;doSthOnDataBase(strSQL);}(SQL只是一个例子)staticconst只会被初始化一次,但会一直保存在内存中直到进程结束。c

c++ - "static functions with block scope are illegal"错误取决于初始化样式?

我有一个类Library,其中包含一个结构Transaction,该结构有一个类型为Patron的成员变量。classPatron{public:Patron(){}};classLibrary{public:structTransaction{Patronp;Transaction(Patronpp):p(pp){}Transaction();};};对于Transaction的默认构造函数,我有一个函数default_transaction()返回对静态对象的const引用,正如Stroustrup在“编程-原则和实践”中所推荐的使用C++”(第324页);推理:避免在构造函数代码

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++ - 带有显式右值转换运算符的 static_cast

我正在编写一个简单的包装类,我想为包装类型提供显式转换运算符。以下代码使用gcc编译良好classwrap{doublevalue;public:explicitwrap(doublex):value(x){}explicitoperatordouble&&()&&{returnstd::move(value);}};intmain(){wrapw(5);double&&x(std::move(w));//okdouble&&y=static_cast(std::move(w));//clangreportsanerrorhere}但是clang报告error:cannotcastfr