C ++风格问题(OOP) [英] C++ style questions (OOP)

查看:51
本文介绍了C ++风格问题(OOP)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,这是交易。我有一个很好的类定义和一大堆

的内联函数,可以在同一个文件中使用它。我的问题

是,我是否需要一个类的实现文件,即使我有每个函数的内联

?或者我可以只使用该类和

它作为实际使用类

和已定义函数的程序的头文件内联?

虽然我在这里,我也不妨问这个。这是我在上面讨论的同一个类中的函数




inline int Startup(void){

短暂退出;

std :: cout<< 欢迎来到代理系统Neo \ n; IO的东西

std :: cout<< 你想继续吗?(y / n)\ n" ;;

while(quit!=''y'')&& (退出!=''Y'')

(退出!=''n'')&& (退出!=''N''){

if(std :: cin<<''y''){

std :: cout< < Please wait \ n;

} else(std :: cin<<''n''){

Close(); //调用Close()函数

}


这不会编译。 gcc说我不能使用

短暂退出;

因为它还没有被宣布。我不必私下申报

对吗?我试过了,它没有工作,我得到了同样的错误。

如何循环结构,我在这里做错了吗?在按钮

''和''运算符之前的while循环''quit''之前,我也得到一个

解析错误。

提前感谢您的帮助,非常感谢。

neo88

Ok, here''s the deal. I have a nice class definition and a whole bunch
of inline functions to go along with it in the same file. My question
is, do I need an implementation file for the class, even though I have
an inline for every single function? Or can I just use the class and
it''s inlines as a header file for programs that actually use the class
and defined functions?
While I''m here I might as well ask this one too. Here is a function
that I have in the same class that I was talking about above:

inline int Startup(void) {
short quit;
std::cout << "Welcome to the Agent system Neo\n"; IO stuff
std::cout << "Do you wish to continue?(y/n)\n";
while (quit != ''y'') && (quit != ''Y'')
(quit != ''n'') && (quit != ''N'') {
if (std::cin << ''y'') {
std::cout << "Please wait\n";
} else (std::cin << ''n'') {
Close(); // calls Close() function
}

This won''t compile. The gcc says that I can''t use the
short quit;
because it hasn''t been declared. I don''t have to declare it private
right? I tried that and it didn''t work, I got the same error. How is
the loop structure, am I doing something wrong here? I also get a
parse error before ''quit'' in the while loop just before the bitwise
''and'' operator.
Thanks in advance for any help, it is greatly appreciated.
neo88

推荐答案

neo88写道:
neo88 wrote:
inline int Startup(void){
short quit;
std :: cout<< 欢迎来到代理系统Neo \ n; IO的东西
std :: cout<< 你想继续吗?(y / n)\ n" ;;
while(quit!=''y'')&& (退出!=''Y'')
(退出!=''n'')&& (退出!=''N''){
if(std :: cin<<''y''){
std :: cout<< 请等待\ n;;
} else(std :: cin<<''n''){
Close(); //调用Close()函数


这不会编译。 gcc说我不能使用
短暂退出;
因为它还没有被宣布。
inline int Startup(void) {
short quit;
std::cout << "Welcome to the Agent system Neo\n"; IO stuff
std::cout << "Do you wish to continue?(y/n)\n";
while (quit != ''y'') && (quit != ''Y'')
(quit != ''n'') && (quit != ''N'') {
if (std::cin << ''y'') {
std::cout << "Please wait\n";
} else (std::cin << ''n'') {
Close(); // calls Close() function
}

This won''t compile. The gcc says that I can''t use the
short quit;
because it hasn''t been declared.




现在来吧。难道不是真的说初始化吗?

是不是?您认为退出的价值是什么?你第一次使用它时有

吗?


-

问候,

巴斯特。



Come on now. Didn''t it really say "initialized"?
Is it right? What value do you think "quit" has
when you first use it?

--
Regards,
Buster.


neo88写道:
neo88 wrote:
inline int Startup(void){
short quit;
std :: cout<< 欢迎来到代理系统Neo \ n; IO的东西
std :: cout<< 你想继续吗?(y / n)\ n" ;;
while(quit!=''y'')&& (退出!=''Y'')
(退出!=''n'')&& (退出!=''N''){
if(std :: cin<<''y''){
std :: cout<< 请等待\ n;;
} else(std :: cin<<''n''){
Close(); //调用Close()函数


这不会编译。 gcc说我不能使用
短暂退出;
因为它还没有被宣布。
inline int Startup(void) {
short quit;
std::cout << "Welcome to the Agent system Neo\n"; IO stuff
std::cout << "Do you wish to continue?(y/n)\n";
while (quit != ''y'') && (quit != ''Y'')
(quit != ''n'') && (quit != ''N'') {
if (std::cin << ''y'') {
std::cout << "Please wait\n";
} else (std::cin << ''n'') {
Close(); // calls Close() function
}

This won''t compile. The gcc says that I can''t use the
short quit;
because it hasn''t been declared.




现在来吧。难道不是真的说初始化吗?

是不是?您认为退出的价值是什么?你第一次使用它时有

吗?


-

问候,

巴斯特。



Come on now. Didn''t it really say "initialized"?
Is it right? What value do you think "quit" has
when you first use it?

--
Regards,
Buster.


" neo88" <所以**** @ truevine.net>写了
"neo88" <so****@truevine.net> wrote
好的,这是交易。我有一个很好的类定义
和一大堆内联函数在同一个文件中与它一起使用
。我的问题是,我是否需要
类的实现文件,即使我对每个函数都有内联?或者我可以只使用该类,它是内联作为头文件
实际使用该类和
定义函数的程序?
Ok, here''s the deal. I have a nice class definition
and a whole bunch of inline functions to go along
with it in the same file. My question is, do I need
an implementation file for the class, even though I
have an inline for every single function? Or can I
just use the class and it''s inlines as a header file
for programs that actually use the class and
defined functions?




您可以只使用头文件,但是最好使用

a对应的.cpp文件,即使它只是将头文件包含为

a健全检查。随着项目的增长,您可能会发现某些功能,无论是旧的还是新的,可能更好地放置在线外,或者您可能想要添加

版本信息到静态字符串或编译时检查中的文件或

静态支持函数等。您将来所做的任何更改将会影响您的库和/或应用程序已构建。另外,除非你清楚地评论它,否则只看到听众文件的人可能会浪费时间来寻找.cpp文件。一致的构建结构具有价值。


Claudio Puviani



You could get away with just the header file, but it''s good practice to have
a corresponding .cpp file, even if all it does is include the header file as
a sanity check. As your project grows, you might find that some functions,
old or new, might be better placed out-of-line or you might want to add
version information to the files in static strings or compile-time checks or
static support functions, etc.. Any changes you make in the future will then
affect how your libraries and/or applications are built. Also, unless you
comment it clearly, someone who only sees the hearder file might waste time
looking for the .cpp file. There''s value in a consistent build structure.

Claudio Puviani


这篇关于C ++风格问题(OOP)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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