草庐IT

read_inheritable_attribute

全部标签

c++、cscope、ctags 和 vim : Finding classes that inherit from this one

在具有几层的相当大的代码库中,有没有办法在vim或命令行中找到从基类派生的所有类?grep是一个选项,但可能会很慢,因为grep没有索引。 最佳答案 cscope和ctags都不允许我们直接处理继承,但是相对解决这个限制是很容易的,因为派生类也被索引了。控制范围在cscope中,寻找“C符号”Foobar通常会列出原始类和继承自它的类。由于搜索是针对数据库完成的,因此速度快如闪电。或者,您可以使用cscope的egrep搜索功能和类似:.*Foobar的模式来列出仅继承自Foobar的类。因此,即使我们没有专门的“查找继承自此类的类

C++ : union of two types without virtual base class inheritance

是否可以在不手动创建交集类型的情况下创建两种类型的并集?问题是在我的上下文中交集类是完全没有意义的,所以创建它会使代码用户感到困惑。我的实际案例:我正在描述一个数字硬件模拟器,它是许多模块的分层树状结构:classport;classmodule0{porta,b,c;}classmodule1{portc,d,e;}我需要创建这两种类型的union:classtop_level_module{porta,b,c,d,e;}我想应该有一些技术来创建union类型(这是我要问的问题):classtop_level_module:union_type{//porta,b,c,d,e;}但是

c++ - boost ASIO async_read_some

我在实现一个简单的TCP服务器时遇到了困难。以下代码摘自boost::asioexamples,准确地说是“Http服务器1”。voidconnection::start(){socket_.async_read_some(boost::asio::buffer(buffer_),boost::bind(&connection::handle_read,shared_from_this(),boost::asio::placeholders::error,boost::asio::placeholders::bytes_transferred));}voidconnection::ha

c++ - 如何正确链接 boost::mpl::inherit_linearly 和 boost::mpl::inherit 以便解析占位符?

假设我有这些类型:templateclassStorage>structAbstractFactoryUnit{virtual~AbstractFactoryUnit(){}virtualtypenameStorage::StoredTypedoCreate(Storage)=0;};和templateclassProductStorage,templateclass>classUnit=AbstractFactoryUnit>structAbstractFactory:boost::mpl::inherit_linearly>>::type{typedefTypeSequencePr

c++ - 为什么 ifstream::read 比使用迭代器快得多?

事实上,有很多方法可以将文件读入字符串。两个常见的是使用ifstream::read直接读取字符串,以及使用steambuf_iterators和std::copy_n:使用ifstream::read:std::ifstreamin{"./filename.txt"};std::stringcontents;in.seekg(0,in.end);contents.resize(in.tellg());in.seekg(0,in.beg);in.read(&contents[0],contents.size());使用std::copy_n:std::ifstreamin{"./fil

c++ - 在 g++ 中使用 __attribute__ 的不平衡括号

今天我在前段时间开发的一个项目上尝试了clang。当它遇到编译错误时我很惊讶,因为我已经使用g++成功编译了我的项目。这个简短的片段重现了遇到错误的行:intmain(){__attribute__((aligned(16))chararr[5];}产生此错误的原因:test.cpp:2:32:error:expected')'__attribute__((aligned(16))chararr[5];^)如您所见,有一个不平衡的括号。有三个“(”和两个“)”。这显然看起来应该会产生编译错误。这是该关键字的有效用法吗?我似乎无法在thedocumentation上找到任何内容这表明它是

c++ - 我什么时候使用 "__attribute__((nonnull))"与 "not_null<T*>"?

我习惯于使用__attribute__((nonnull))表达不应为空的指针时。voidf(int*ptr)__attribute__((nonnull));intmain(){int*ptr=newint(1);f(ptr);}voidf(int*ptr){/*impl*/}但是,对于GSL,还有not_null包装类型。voidfunction1(gsl::not_nulln);voidf(gsl::not_nulln);intmain(){int*ptr=newint(1);f(ptr);}voidf(gsl::not_nulln){/*impl*/}假设语言设施支持GSL版本

c++ - 异常错误 : Access violation reading location 0xDDDDDDDD

我正在尝试用C++创建一个动态字符串数组。当尝试将我的动态字符串数组的内容显示到控制台时,我收到此错误:Exceptionthrownat0x0FD670B6(msvcp140d.dll)inAssignment4.exe:0xC0000005:Accessviolationreadinglocation0xDDDDDDDD.这是我的代码:DynamicStringArray.h#pragmaonce#include"stdafx.h"#include#includeusingnamespacestd;classDynamicStringArray{public:DynamicStri

c++ - Valgrind: "Invalid read"与 c_str 和 strtod

我正在使用strtod()来转换一些输入字符串。在用valgrind检查我的代码时,我遇到了“大小为8的无效读取”。如果b以“i”或“n”开头,则会显示该消息,这就是我到目前为止所发现的。另外,如果我直接创建一个constchar*(不调用c_str()),strtod似乎也可以。这是代码:#include#includeintmain(intargc,char**argv){char*a=0;std::stringb="i";constchar*c=b.c_str();doubled=strtod(c,&a);}和(详细的)valgrind输出:==12638==Memcheck,a

c++ - 使用 boost::asio::read_async 读取 Protobuf 对象

我正在使用Boostasio编写一个应用程序,其中客户端和服务器交换使用googleproto-buffers序列化的消息。我不知道通过网络发送的序列化消息的大小是多少。proto-buf对象似乎没有任何分隔符。这是.proto文件的内容。packagetutorial;messagePerson{requiredstringname=1;requiredint32id=2;optionalstringemail=3;}这是我从服务器写的方式tutorial::Personp;p.set_name("abcdpqrs");p.set_id(123456);p.set_email("ab