草庐IT

using-declaration

全部标签

c++ - 错误 : no '__________' member function declared in class '_______'

我认为自己是一个相当新手的c++程序员,我以前从未遇到过这个错误。我只是想为我的函数创建一个类,但我的头文件中声明的所有std::前缀函数都没有被识别//comments//comments//comments//comments//comments//comments//comments//comments//comments//comments//comments#ifndefPERSON_H#definePERSON_H#includeclassPerson{public:Person();std::stringgetName();//returnfirstnamestd::st

c++ - Q_DECLARE_METATYPE 一个 boost::multi_array

我正在尝试使用Qt的信号和槽机制传递表示为boost::multi_array的多维数组。我尝试使用以下代码段声明元类型:Q_DECLARE_METATYPE(boost::multi_array)但是我得到以下编译错误(在MSVC2015上):path\to\project\metatypes.h(7):errorC2976:'boost::multi_array':toofewtemplatearguments..\..\ml_project\boost-libs\include\boost/multi_array.hpp(111):note:seedeclarationof'bo

c++ - 详细命名空间中的 using 指令是否有问题?

考虑这个库头:#include#include#includenamespaceLib{namespacedetail{usingnamespacestd;templatevoidsort_impl(istream&in,ostream&out){vectorv;{intn;in>>n;v.resize(n);}for(auto&i:v)cin>>i;sort(v.begin(),v.end());for(autoi:v)out(std::cin,std::cout);}}在此示例中,detail命名空间是否成功地将库的客户端(以及库的其余实现)与using-directive隔离开来

C++ API 设计 : is using void* a bad idea?

我正在开发一个我希望在调用方尽可能通用的API。主要设计思想是提供一种信号/插槽类型的实现,允许API的用户订阅一组给定的事件,并将用户定义的回调附加到它们。公共(public)界面看起来像这样:RetCallbacksubscribe(EventEnum&ev,std::functionfn)const;:注意void(void*)在这里签名。EventEnum在公共(public)头文件中给出,以及类型定义。然后,API的内部工作将通过通知方法将事件通知其订阅的观察者,并提供要转发给客户端的数据:voiddummyHeavyOperation()const{std::this_th

c++ - 在 C++ 头文件中放置 using 指令的位置

对于我的项目,我使用了一些非常复杂的数据结构,例如std::unordered_map>>为了可读性,我想为其声明类型别名。我构建项目的代码已经通过在头文件中全局放置using语句来做到这一点://bar.h#ifndefBAR_H#defineBAR_H#include#include#include#include"foo.h"usingFooTable=std::unordered_map>>;classBar{FooTablecreate_foo();};#endif因为我的C++知识有点生疏,所以我只是采用了这种风格——但现在我读到以这种方式使用using可能会有问题,因为它

c++ - 转发声明结构时出错 : "has a previous declaration here"

在构建我的小型C++项目时,出现以下2个错误,无法找出原因:错误:在“结构”之后使用类型定义名称“TTF_Font”。指向Foo.h中的以下代码行:structTTF_Font;。错误:“TTF_Font”在此之前有一个声明。指向以下代码行:typedefstruct_TTF_FontTTF_Font;inSDL_ttf.h。我已将其缩小到新测试项目中的以下文件:Foo.h:#ifndefFOO_H#defineFOO_HstructTTF_Font;classFoo{TTF_Font*font;};#endif//FOO_HFoo.cpp:#include"Foo.h"#includ

c++ - 嵌套模板特化结果为 "Illegal use of explicit template arguments"?

如何专门化嵌套模板?(请参阅下面的错误。)usingstd::reverse_iterator;templatereverse_iteratormake_reverse_iterator(constIt&it){returnreverse_iterator(it);}templateItmake_reverse_iterator>(constreverse_iterator&it){//Above^//errorC2768://'make_reverse_iterator':illegaluseofexplicittemplateargumentsreturnit.base();}

Using Where,Using index,Using index condition

首先回顾一下这三个的定义定义回顾Usingwhere当有where条件,但是不能使用索引或者使用索引后仍需扫描全表或者索引树判断条件的情况,简单来说,有效的where条件就Usingwhere。Usingindex索引覆盖,索引树已包含所有需要的数据,无需回表查询Usingindexcondition官方文档:https://dev.mysql.com/doc/refman/8.0/en/index-condition-pushdown-optimization.html索引条件下推(IndexConditionPushdown,ICP)是MySQL使用索引的情况的优化。简单来说,在服务器需要

c++ - 冒号 : used in variable initialization?

这个问题在这里已经有了答案:Whatdoesacoloninastructdeclarationmean,suchas:1,:7,:16,or:32?(3个答案)关闭7年前。我找到这条线here:uint32bIsHungry:1;...而且我从未见过这种用于初始化变量的语法。我已经习惯看到这个了:uint32bIsHungry=1;它看起来有点像一个初始化列表,但是对于单个字段?它是什么,它有什么作用,我为什么要关心?

c++ - 编程 : Principles and Practice Using C++ chapter 4 drill step 6 : General question about numeric range

我想提示用户输入一些double值,然后存储最小值和最大值,然后打印文本。这是我到目前为止的代码:#include#include#include#includeusingnamespacestd;intmain(){doublemin=1000000000;//Hereismyissue!doublemax=-100000000;//Hereismyissue!for(doubleinput;cin>>input;){if(input=='|')return0;elseif(inputmax){max=input;cout所以我的代码工作正常并且做我想做的,但我对处理双最小值和最大值