草庐IT

tree_type

全部标签

Qt : has initializer but incomplete type 中的 C++ 错误

voidFindWords::getTextFile(){QFilemyFile(":/FindingWords2.txt");myFile.open(QIODevice::ReadOnly);QTextStreamtextStream(&myFile);QStringline=textStream.readAll();myFile.close();ui->textEdit->setPlainText(line);QTextCursortextCursor=ui->textEdit->textCursor();textCursor.movePosition(QTextCursor::S

c++ - "' void* ' is not a pointer-to-object type"在没有 void* 的代码中?

我的代码有问题。在Xcode或使用C++11编译器中,此代码运行良好。但是,当我将此代码提交给在线法官时,判决显示“编译错误”。我认为他们使用的是C++4.7.1编译器,当我尝试编译它(使用Ideone)时,它说:prog.cpp:Infunction'voidprintArray(int)':prog.cpp:27:error:'void*'isnotapointer-to-objecttypeprog.cpp:27:error:'void*'isnotapointer-to-objecttypeprog.cpp:27:error:'void*'isnotapointer-to-ob

c++ - "missing type specifier"构造函数声明错误

我在2个不同的文件中有2个类:正则矩阵.h:#ifndef_RM_H#define_RM_H#include"SparseMatrix.h"...classRegMatrix{...RegMatrix(constSparseMatrix&s){...}//ctor...};#endif稀疏矩阵.h:#ifndef_SM_H#define_SM_H#include"RegMatrix.h"...classSparseMatrix{...SparseMatrix(constRegMatrix&r){...}//ctor...};#endif在构造函数行上我得到了错误:错误C4430:缺少类

c++ - 错误 :incompatible types in assignment of 'const char[5]' to 'char[10]'

我已经将c定义为charc[][10]在函数定义中并像c[i]="gray";一样使用它怎么了?我在网上搜索,它显示相同的语法。谢谢。 最佳答案 您不能对数组使用赋值(=)。如果将c更改为指针数组,这可能会起作用,具体取决于您需要使用它做什么。constchar*c[20];c[i]="gray";或者如果声明的类型必须是数组的数组,您可以使用strncpy:charc[20][10];strncpy(c[i],"gray",sizeof(c[i])); 关于c++-错误:incompa

c++ - 如何根据变量值惯用地调用 C++ 函数?

假设我有一个数据类型enumTreeTypes{TallTree,ShortTree,MediumTree}。而且我必须根据一种特定的树类型初始化一些数据。目前我写了这段代码:intinitialize(enumTreeTypestree_type){if(tree_type==TallTree){init_tall_tree();}elseif(tree_type==ShortTree){init_short_tree();}elseif(tree_type==MediumTree){init_medium_tree();}returnOK;}但这是某种愚蠢的代码重复。我没有使用任何

c++ - 错误 : Variable length array of Non-POD element type 'string'

在开始之前,我必须首先声明,我已经研究过针对此错误的可能解决方案。不幸的是,它们都与不使用数组有关,这是我项目的要求。另外,我目前正在学习CS入门类(class),所以我的经验几乎没有。数组的用途是从文件中收集名称。因此,为了初始化数组,我计算了名称的数量并将其用作大小。问题是标题中所述的错误,但我仍然使用一维数组时看不到解决方法。主要.cpp#include#include#include#include#include#include"HomeworkGradeAnalysis.h"usingnamespacestd;intmain(){ifstreaminfile;ofstrea

c++ - 代码综合——C++/Tree子节点序列化

我正在使用这个很棒的工具(http://www.codesynthesis.com/products/xsd/c++/tree/)将xsd转换为C++代码。我试图从子节点获取xml字符串,但我唯一能得到的是所有xml,如下所示:所有的xml:John.......我可以让所有的xml做这样的事情:people_t&p=...xml_schema::namespace_infomapmap;map[""].schema="people.xsd";//Serializetoastring.//std::ostringstreamoss;people(oss,p,map);std::stri

c++ - 这是 "new auto(enum_type)"的 Microsoft VC++ 2010 编译器错误吗

环境:MicrosoftVisualStudio2010withSP1Preminum(10.0.40219.1SP1Rel),WindowsXPSP3VC10编译器支持auto关键字,但推导的类型相关信息对于枚举似乎并不总是正确的。例子:#includeenumfruit_t{apple=100,banana=200,};intmain(){constautopa=newauto(banana);constautopb=newfruit_t(banana);static_assert(std::is_same::value,"notsame!");deletepb;deletepa;

C++ 模板 "class type"错误

我一直在研究一个链表模板类来对各种变量做同样的事情,并设法解决了大部分问题。除了编译时,我得到这些:g++-Wall-otemplate_testtemplate_test.cppInfileincludedfromtemplate_test.cpp:1:0:LinkedList.h:50:11:error:declarationof‘classType’LinkedList.h:7:11:error:shadowstemplateparm‘classType’LinkedList.h:51:30:error:invaliduseofincompletetype‘classLinked

c++ - 如何填充 'Tree' 结构 'Declaratively'

我想定义一个“节点”类/结构,然后在代码中声明这些节点的树,使代码格式化的方式反射(reflect)树结构,并且没有“太多”样板的方式。请注意,这不是关于数据结构的问题,而是关于我可以使用哪些C++功能来获得与以下示例类似的声明式代码风格的问题。可能使用C++0X这会更容易,因为它在构建对象和集合方面具有更多功能,但我使用的是VisualStudio2008。示例树节点类型:structnode{stringname;node*children;node(constchar*name,node*children);node(constchar*name);};我想做什么:声明一棵树,使