“ ClassName ClassName :: FunctionName”是什么?在C ++中意味着什么? [英] What does "ClassName ClassName::FunctionName" mean in C++?

查看:102
本文介绍了“ ClassName ClassName :: FunctionName”是什么?在C ++中意味着什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我阅读c ++代码时,总是看到形式为 ClassName ClassName :: FunctionName的代码。例如:

When I read c++ code, I keep seeing code of the form "ClassName ClassName::FunctionName." For example:

Fraction Fraction:: Reciprocal() {       

    return Fraction(denominator,numerator);
}

上面的分数是一个类名,Reciprocal()是一个在内部声明的函数分数类,并且有一个带有两个参数的构造函数。使用这种格式的意义是什么?

In above Fraction is a class name and Reciprocal() is a function declared inside fraction class and there is a constructor with two parameters. What is the significant of using this format?

推荐答案

,这意味着First Fraction指示返回类型就像void,double ,int等。。。您正在返回分数,第二个分数是让编译器知道函数Reciprocal()是分数类中的一个,就是这样,不要被它的外观所束缚,它很简单,如果您想阅读更多有关它的内容,请尝试获取绝对c ++,这是一本好书。

so that means that the First Fraction indicates the return type just like void, double, int etc.... you are returning Fraction, and the second Fraction is the let the compiler know the function Reciprocal() is the one from the Fraction class, that's it, don't be trussed by the way it looks, it is simple as that, if you want to read more up on it try to get the "absolute c++" it is a good book.

这篇关于“ ClassName ClassName :: FunctionName”是什么?在C ++中意味着什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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