与C ++ OOP混淆了 [英] Got confused with C++ OOP

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

问题描述

Buckys C ++编程教程 - 42 - Arrow会员选择运营商 - YouTube [ ^ ]



所以你看到这里他有3个文件:main.cpp,Sally.h和Sally.cpp,他在Sally.cpp文件中定义了一个void函数,语法为void Sally :: printCrap()。我很困惑,为什么他要把类的名称用于在类外定义一个函数?有人可以解释一下吗。我真的很感激!



我的尝试:



对于小而不详细的问题很抱歉,但我限于200个字符:XI希望你理解我的问题,并希望你能解释我。





谢谢!

Buckys C++ Programming Tutorials - 42 - Arrow Member Selection Operator - YouTube[^]

So you see here he has 3 files: main.cpp, Sally.h and Sally.cpp and he is defining a void function in the Sally.cpp file with syntax void Sally::printCrap(). I got confused in that why he is putting the name of the class for defining a function in outside the class ? Can someone explain me that. I will be really thanksful!

What I have tried:

Sorry for the small and not detailed question but I am limited to 200 characters :X I hope you understood my question and hope you will explain me that.


Thanks!

推荐答案

Sally :: printCrap()是因为printCrap是在Sally类之外定义的。如果它是在类内部定义的(内联),它就不必拥有Sally ::



如果你没有'Sally ::',那么编译器就不会知道函数属于哪个类。
The Sally::printCrap() is because printCrap is defined outside the Class Sally. If it were defined inside the class (inline) it would not have to have Sally::

If you dont have 'Sally::', then the compiler would not know which class the function belonged to.


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

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