gpt4 book ai didi

c++ - 如何返回与函数在同一类中声明的结构?

转载 作者:行者123 更新时间:2023-11-27 23:10:08 25 4
gpt4 key购买 nike

我的头文件中有一个类声明,如下所示。一个函数使用一个结构作为输入,另一个作为返回参数。关键是当我以这种方式使用时,编译器会给我错误。

会是什么原因呢?任何想法表示赞赏。

#include <string>

using namespace std;

namespace My_Functions
{
class My_Functions
{

public:
struct {

char input_a;
int input_b;
double input_c;
double input_d;
double input_e;
double input_f;
double input_g;

} Input_Parameters;

struct {

char output_a;
int output_b;
double output_c;
double output_d;
int output_e;

} Output_Parameters;

public:
Output_Parameters FindExit(Input_Parameters input);


};

}

在cpp文件中

My_Functions::Output_Parameters My_Functions::FindExit(My_Functions::Input_Parameters input)
{

}

最佳答案

可以通过三种方法解决您的问题。

一个。 struct struct_name {}; -> 这个声明的结构名为“structure_name”

B. typedef struct {}struct_name; -> 如果您不想在结构之前使用 'struct' 关键字,那么在结构之前使用 typedef 会很有用姓名。

C.在函数原型(prototype)中使用 struct 关键字。

struct Output_Parameters FindExit(struct Input_Parameters input);

A 的例子:

    struct Input_Parameters {

char input_a;
int input_b;
double input_c;
double input_d;
double input_e;
double input_f;
double input_g;

} ;

struct Output_Parameters{

char output_a;
int output_b;
double output_c;
double output_d;
int output_e;

};

关于c++ - 如何返回与函数在同一类中声明的结构?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20843564/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com