标签: declaration

获取错误:ISO C++禁止声明无类型

我收到以下错误:

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)

任何人都可以指出导致这些错误的原因吗?谢谢!

c++ constructor class declaration function

32
推荐指数
2
解决办法
10万
查看次数

为什么不能在do while循环的表达式部分中声明变量?

以下语法有效:

while (int i = get_data())
{
}
Run Code Online (Sandbox Code Playgroud)

但以下不是:

do
{
} while (int i = get_data());
Run Code Online (Sandbox Code Playgroud)

我们可以通过标准草案N41406.4节了解原因:

1 [...]

condition:
     expression
     attribute-specifier-seqopt decl-specifier-seq declarator = initializer-clause
     attribute-specifier-seqopt decl-specifier-seq declarator braced-init-list

2条件规则既适用于选择陈述,也适用于forwhile陈述(6.5).[...]

和第6.5

1迭代语句指定循环.

      iteration-statement: 
             while ( condition ) statement
             do statement while ( expression ) ;

相反,你被迫做一些丑陋的事情:

int i = get_data();
do
{
} while ((i = get_data())); // double parentheses sic
Run Code Online (Sandbox Code Playgroud)

这是什么理由?

c++ declaration do-while

32
推荐指数
4
解决办法
5260
查看次数

这两个结构声明有什么区别?

我对不同教程中的这两种结构感到困惑:

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?一般情况是怎样的?

c c++ struct typedef declaration

32
推荐指数
3
解决办法
3904
查看次数

为什么#include <stdio.h>不需要使用printf()?

会议记录:

>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)

c printf declaration include

31
推荐指数
3
解决办法
4万
查看次数

将C++类的定义放入头文件是一个好习惯吗?

当我们用Java,Vala或C#设计类时,我们将定义和声明放在同一个源文件中.但在C++中,传统上优先将两个或多个文件中的定义和声明分开.

如果我只使用头文件并将所有内容放入其中,如Java,会发生什么?是否存在性能损失?

c++ declaration definition header-files

31
推荐指数
2
解决办法
2万
查看次数

x的多个声明

我有这个代码,它不会编译,突出显示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)

haskell declaration

31
推荐指数
2
解决办法
5983
查看次数

字符串与字符串

在C#中有String对象和string对象.

两者有什么区别?有关使用哪种方法的最佳做法是什么?

.net c# string declaration

29
推荐指数
3
解决办法
3460
查看次数

C++:为什么必须声明私有函数?

为什么C++中的类必须声明它们的私有函数?它有实际的技术原因(它在编译时的作用是什么)还是仅仅为了一致性?

c++ private class declaration function

29
推荐指数
2
解决办法
1万
查看次数

C多个单行声明

当我宣布在一行上说多个变量时会发生什么?例如

int x, y, z;
Run Code Online (Sandbox Code Playgroud)

一切都是整体.问题是以下陈述中的y和z是什么?

int* x, y, z;
Run Code Online (Sandbox Code Playgroud)

它们都是int指针吗?

c variables declaration

28
推荐指数
3
解决办法
2万
查看次数

在C中为数组分配多个值

有没有办法以浓缩形式这样做?

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, ...};

c arrays initialization declaration

28
推荐指数
3
解决办法
9万
查看次数