草庐IT

c++ - C 和 C++ header : Define global struct inside of another struct

我有一些C代码,其中有一些结构如下所示:typedefstructmy_library_a_tmy_library_a_t;typedefstructmy_library_b_tmy_library_b_t;typedefstructmy_library_c_tmy_library_c_t;structmy_library_a_t{structmy_library_b_t{intdata;structmy_library_c_t{intdata;}c;}b;intdata;};这在C++中不起作用,因为在C中structmy_library_b_t定义了一个全局structmy_lib

c++ - "expected ' : ', ' , ', ' ; ', ' } ' or ' __attribute__ ' before ' { 结构成员函数中的' token"

我正在尝试编译我教授设计过度的C++代码。这是我的代码:/***Vectorclass.*CommonmathematicaloperationsonvectorsinR3.**WrittenbyRobertOsada,March1999.**/#ifndef__VECTOR_H__#define__VECTOR_H__/***Vector3**/structVector3f{//coordinatesfloatx,y,z;//normfloatnormSquared(){returnx*x+y*y+z*z;}doublenorm(){returnsqrt(normSquared())

c++ - 在 qsort 之后识别项目/类指针

第一个问题,所以请原谅我的天真。我正在研究用于C++的三角剖分库,它在运行它的三角剖分方法之前对结构指针数组进行排序。我试图在我的应用程序中跟踪一个特定的结构指针(XYZ),它会根据鼠标位置进行更新。问题是,无论何时应用qsort方法,这个指针都会改变。我如何识别或跟踪此结构XYZ指针?这是结构和排序...structXYZ{doublex,y,z;};intXYZCompare(constvoid*v1,constvoid*v2){XYZ*p1,*p2;p1=(XYZ*)v1;p2=(XYZ*)v2;if(p1->xx)return(-1);elseif(p1->x>p2->x)re

c++ - 读取 mex 文件中的结构数据时发生奇怪的事情

我刚才被一个很奇怪的mex错误搞糊涂了。..将我的问题归结为核心,我们最终得到以下简单的mex代码。它只显示给定的结构字段是否为空...#include"mex.h"voidmexFunction(intnlhs,mxArray*plhs[],intnrhs,constmxArray*prhs[]){intnumElements=mxGetNumberOfElements(prhs[0]);intnumFields=mxGetNumberOfFields(prhs[0]);mxArray*tmpData;constchar*tmpName;for(intstructIdx=0;stru

c++ - C++ 和 cin.getline 的问题

我正在用C++学习struct,我不知道如何让它不跳过第一个问题。如果我在struct中使用char,它只会复制第一个单词,如果我尝试使用string,它会跳过第一个问题(忽略它)。你能指导我吗?稍后编辑:我使用MicrosoftVisualC++2010ExpressEdition,std::getline和cin.getline有区别吗?#include#include#includeusingnamespacestd;structmelodie{charartist[50];chartitlu[50];intan;intlungime;};voidmain(){intrepeta

c++ - 远程读写结构

我目前正在构建一个附有一些传感器的机器人。机器人上的控制单元是ARMCortex-M3,所有传感器都附在上面,并通过以太网连接到“地面站”。现在我想通过地面站读写机器人的设置。于是我想到了在机器人上实现一个可以被地面站操控的“虚拟寄存器”。它可以由结构组成,看起来像这样://accelerometerregisterstructaccel_reg{//accelerationsint32_taccelX;int32_taccelY;int32_taccelZ;};//infrareddistancesensorregisterstructir_reg{uint16_tdist;//di

c++ - 通过别名定义前向定义的 C++ 结构

我想围绕现有的C++代码库编写一个C包装器。所以我需要实现一些C-API函数,这些函数仅将它们的操作转发给相应的C++方法。我的问题是,我不知道如何通过现有类实现前向定义的结构://Foo.hppnamespacemyLib{structFoo{//somemeaningfulC++body};}//foo.h//#ifdef__cplusplusetc.leftoutextern"C"{structmyLib_foo;myLib_foo*mkfoo();//etc.}//foo.cppextern"C"{#include"Foo.hpp"#include"foo.h"typedefm

c++ - 重用存储是否开始新对象的生命周期?

这个问题在这里已经有了答案:IsitallowedtowriteaninstanceofDerivedoveraninstanceofBase?(4个答案)关闭8年前。#includestructB{virtualvoidf();voidmutate();virtual~B();};structD1:B{voidf();};structD2:B{voidf();};voidB::mutate(){new(this)D2;//reusesstorage—endsthelifetimeof*thisf();//undefinedbehavior-WHY????...=this;//OK,t

c++ - 有没有办法在用户定义的转换中指定优先级?

免责声明:我知道通常不鼓励使用用户定义的隐式转换。但是,在我们的项目中,我们需要各种模板类的这些转换才能相互很好地协同工作。我需要定义用户定义转换的优先级,例如:structX{}structY{}structZ{operatorX(){...}operatorY(){...}}voidfoo(Xx){...}voidfoo(Yy){...}//somewhereinsometemplateclientcode...{Zz=...;...foo(z);//WILLNOTCOMPILE}这不会编译,因为从Z到X或Y的转换是不明确的。有没有办法解决这种歧义。即,我能否以某种方式告诉编译器:

c++ - 第一个索引后未填充结构数组索引

我有一个输入文件,每行有3个字段,类型为:string、double、double。有15行数据。输入文件数据的格式为:加德满都,-34、28城市名称、低温、高温.........很明显,根据输出,它没有获得线路上的第三个输入。代码如下:for(intindex=0;index>weatherInfo[index].low>>weatherInfo[index].high;inFile.ignore(std::numeric_limits::max(),'\n');}出于某种原因,这是我的输出:Katmandu(-34,0)(0,0)(0,0)(0,0)(0,0)(0,0)(0,0)(