C ++:在头文件中声明结构返回类型函数 [英] C++ : Declaring struct return-type function in header file

查看:64
本文介绍了C ++:在头文件中声明结构返回类型函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个头文件" check.h ",它定义了以下 struct :

I have a header file "check.h" that defines the following struct:

#ifndef CHECK_H
#define CHECK_H
#include<string>
struct Test{
    std::string check;

};

#endif  

我还有另一个头文件" test.h ",该文件具有以下功能,返回类型为上面定义的 struct Test :

I have another header file "test.h" that has the following function with return type as the struct Test defined above:

#ifndef TEST_H
#define TEST_H
#include<string>
#include "check.h"
Test display(std::string);
#endif  

但是,即使在此头文件中包含"check.h" ,我也会收到无法解析标识符的错误.我该怎么做才能解决此问题?

But even on including "check.h" in this header file I get an unable to resolve identifier error. What do I do to fix this?

推荐答案

只要没有定义名称为 Test .

如果有的话,则需要明确说明您是在指代类而不是其他东西:

If you have, then you need to make it clear that you're referring to the class and not the other thing:

struct Test display(std::string);
^^^^^^

尽管更好的解决方案是避免对不同的事物使用相同的名称.

although a much better solution would be to avoid using the same name for different things.

这篇关于C ++:在头文件中声明结构返回类型函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆