我收到以下错误:
ISO C++禁止声明ttTreeInsert没有类型
ISO C++禁止在没有类型的情况下声明ttTreeDelete
ISO C++禁止在没有类型的情况下声明ttTreePrint
int ttTree的原型:: ttTreePrint()与类ttTree中的任何一个都不匹配
候选人是:void ttTree :: ttTreePrint()
这是我的头文件:
#ifndef ttTree_h
#define ttTree_h
class ttTree
{
public:
ttTree(void);
int ttTreeInsert(int value);
int ttTreeDelete(int value);
void ttTreePrint(void);
};
#endif
Run Code Online (Sandbox Code Playgroud)
这是我的.cpp文件:
#include "ttTree.h"
ttTree::ttTree(void)
{
}
ttTree::ttTreeInsert(int value)
{
}
ttTree::ttTreeDelete(int value)
{
}
ttTree::ttTreePrint(void)
{
}
Run Code Online (Sandbox Code Playgroud)
任何人都可以指出导致这些错误的原因吗?谢谢!
以下语法有效:
while (int i = get_data())
{
}
Run Code Online (Sandbox Code Playgroud)
但以下不是:
do
{
} while (int i = get_data());
Run Code Online (Sandbox Code Playgroud)
我们可以通过标准草案N4140第6.4节了解原因:
1 [...]
condition: expression attribute-specifier-seqopt decl-specifier-seq declarator = initializer-clause attribute-specifier-seqopt decl-specifier-seq declarator braced-init-list2条件规则既适用于选择陈述,也适用于
for和while陈述(6.5).[...]
和第6.5节
1迭代语句指定循环.
iteration-statement:while( condition ) statementdostatementwhile( expression ) ;
相反,你被迫做一些丑陋的事情:
int i = get_data();
do
{
} while ((i = get_data())); // double parentheses sic
Run Code Online (Sandbox Code Playgroud)
这是什么理由?
我对不同教程中的这两种结构感到困惑:
typedef struct complex {
float real;
float imag;
} COMPLEX;
typedef struct {
float real;
float imag;
} COMPLEX;
COMPLEX c1;
Run Code Online (Sandbox Code Playgroud)
他们都正确吗?为什么?struct 之前是否需要添加小写字母complex?一般情况是怎样的?
会议记录:
>type lookma.c
int main() {
printf("%s", "no stdio.h");
}
>cl lookma.c
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.762 for 80x86
Copyright (C) Microsoft Corporation. All rights reserved.
lookma.c
Microsoft (R) Incremental Linker Version 8.00.50727.762
Copyright (C) Microsoft Corporation. All rights reserved.
/out:lookma.exe
lookma.obj
>lookma
no stdio.h
Run Code Online (Sandbox Code Playgroud) 当我们用Java,Vala或C#设计类时,我们将定义和声明放在同一个源文件中.但在C++中,传统上优先将两个或多个文件中的定义和声明分开.
如果我只使用头文件并将所有内容放入其中,如Java,会发生什么?是否存在性能损失?
我有这个代码,它不会编译,突出显示Point3的x和y右边并写:"x的多个声明"和"y的多个声明".怎么了?Point2和Point3不能拥有相同的成员名称吗?
data Point2 = Point2 {x :: Float, y :: Float}
data Point3 = Point3 {x :: Float, y :: Float, z :: Float}
Run Code Online (Sandbox Code Playgroud) 在C#中有String对象和string对象.
两者有什么区别?有关使用哪种方法的最佳做法是什么?
为什么C++中的类必须声明它们的私有函数?它有实际的技术原因(它在编译时的作用是什么)还是仅仅为了一致性?
当我宣布在一行上说多个变量时会发生什么?例如
int x, y, z;
Run Code Online (Sandbox Code Playgroud)
一切都是整体.问题是以下陈述中的y和z是什么?
int* x, y, z;
Run Code Online (Sandbox Code Playgroud)
它们都是int指针吗?
有没有办法以浓缩形式这样做?
GLfloat coordinates[8];
...
coordinates[0] = 1.0f;
coordinates[1] = 0.0f;
coordinates[2] = 1.0f;
coordinates[3] = 1.0f;
coordinates[4] = 0.0f;
coordinates[5] = 1.0f;
coordinates[6] = 0.0f;
coordinates[7] = 0.0f;
return coordinates;
Run Code Online (Sandbox Code Playgroud)
有点像coordinates = {1.0f, ...};?
declaration ×10
c++ ×5
c ×4
class ×2
function ×2
.net ×1
arrays ×1
c# ×1
constructor ×1
definition ×1
do-while ×1
haskell ×1
header-files ×1
include ×1
printf ×1
private ×1
string ×1
struct ×1
typedef ×1
variables ×1