我想创建一个包含以下结果的头文件。 [英] I wanted to create a header file with the following result.

查看:99
本文介绍了我想创建一个包含以下结果的头文件。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

头文件与其他头文件一起继承为。

--------------首先是头文件---------

The header file is inherited with other header files as.
--------------Header file first---------

#ifndef doing_h
#define doing_h
class doing{
  public:
    doing(int a){......}
    fn_doing1(){.........}
}
#endif





---------- ----头文件第二---------



--------------Header file second---------

#ifndef something_h
#define something_h
class something{
  public:
    something(int a,int b){......}
    fn_something1(){.........}
}
#endif





------------- -Main头文件---------



--------------Main header file---------

ifndef main_header_h
#define main_header_h
#include "doing.h"
#include "something.h"
class main_header : public doing, public something{
  public:
    main_header(){......}
    fn_main_header1(){.........}
}
#endif



现在我想在代码中访问头文件的特定功能




Now in the code i want to access the specific function of the header files as

#include "main_header.h"

main_header DOING(2) //I want the DOING to call the first header constructor and should represent the first header file only

main_header SOMETHING(2,8) //I want the DOING to call the Second header constructor and should represent the first header file only

void main(){
   DOING.fn_doing1(); //can be called
   DOING.fn_something1() //cannot be called
}



如何制作DOING和SOMETHING分别调用第一个和第二个头文件函数。

请建议所有必要的更改和编辑。

请帮助我。



我尝试了什么:



我试过但不能这样做。


How can i make the DOING and SOMETHING call the first and second header file functions respectively.
Please suggest all the necessary changes and editing required.
Please help me.

What I have tried:

I have tried but not able to do so.

推荐答案

您对头文件有一些误解。它们不会被调用,而是由预处理器处理。



阅读维基百科,了解预处理器的详细信息



您想要的更多是通过类和继承完成的。 课程教程



提示:避免多重继承,因为它使一切都有点混乱。更好的是



You have some misunderstanding of header files. They arent getting "called" but processed by the preprocessor.

Read the wikipedia for details of the preprocessor.

What you want is more done with classes and inheritance. A tutorial on classes.

Tip: avoid multiple inheritance, because it makes all a bit messy. Better is

class doing : public something{
//...
};// end doing
class main_header : public doing


这篇关于我想创建一个包含以下结果的头文件。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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