不能在返回类型中定义新类型 - C++

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3198750/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 12:17:26  来源:igfitidea点击:

new types may not be defined in a return type - C++

c++class-designcompilation

提问by jDOG

I am confused I think on C++ class structure.

我很困惑我认为 C++ 类结构。

I have a .h called FxMathFunctions.h and a .cpp called FxMathFunctions.cpp

我有一个名为 FxMathFunctions.h 的 .h 和一个名为 FxMathFunctions.cpp 的 .cpp

the .h starts like:

.h 开头如下:

class  FxMathFunctions
{
    public:
        FxMathFunctions();
        ~FxMathFunctions();

and in the .cpp

并在 .cpp 中

I have:

我有:

#include "FxBasicTypes.h"
#include "FxMathFunctions.h"

FxMathFunctions::FxMathFunctions() {}

FxMathFunctions::~FxMathFunctions() {}

I am getting errors like:

我收到如下错误:

error: new types may not be defined in a return type
error: return type specification for constructor invalid

This must be something to do with definition someplace, but I just dont see where this might occur.

这一定与某个地方的定义有关,但我只是不知道这可能发生在何处。

回答by Chris Pitman

What does your .h file endwith? I'm guessing that the end of your class defnition does not have a ";". The class is being interpreted as the return type of the first function in your cpp file.

你的 .h 文件以什么结尾?我猜你的类定义的末尾没有“;”。该类被解释为 cpp 文件中第一个函数的返回类型。

回答by Kirill V. Lyadvinsky

Losing ;in the end of class declaration could lead to such error.

;在类声明的末尾丢失可能会导致此类错误。

回答by tojas

Class declaration ends with a semicolon.

类声明以分号结束。