将枚举放在cpp程序中的哪里? [英] Where to put the enum in a cpp program?
本文介绍了将枚举放在cpp程序中的哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个使用枚举类型的程序.
I have a program that uses enum types.
enum Type{a,b,};
class A
{
//use Type
};
class B
{
// also use that Type
};
2个类位于2个不同的文件中.我应该将类型定义放在头文件中还是在每个班级的班级定义中?
2 class are located in 2 different files. Should I put the type definition in a headfile or in class definition for each class?
推荐答案
如果枚举将在多个.cpp文件中使用,则应将其放在每个文件都将包含的头文件中.如果有通用的头文件,则应使用该文件,否则也可以为此枚举创建一个新的头文件
If the enum is going to be used in more than one .cpp file, you should put it in a header file that will be included by each. If there's a common header file, you should use that, otherwise you may as well create a new header file for this enum
这篇关于将枚举放在cpp程序中的哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文