“类"返回类型的关键字-C ++ [英] "class" Keyword on Return Type - C++

查看:44
本文介绍了“类"返回类型的关键字-C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一段看起来像这样的代码:

I came across a piece of code that looked like this:

class SomeClass* GetSomeClass()
{
  return _instanceOfSomeClass;
}

"class"关键字对返回类型有什么作用?我找不到任何可以解释其功能的地方.它是否只是在某些模棱两可之类的东西的情况下指定将SomeClass作为一个类来讨论?我很困惑.

What does the "class" keyword do on the return type? I can't find anywhere that explains what it's function is. Does it just specify that it's talking about SomeClass as a class in case there is some sort of ambiguousness or something? I am confused.

推荐答案

class SomeClass 是引用类类型 SomeClass 的一种简便方法(从技术上讲,它是精心设计的类型说明符).通常,添加 class 是多余的,两者是等效的.但是,如果存在具有相同名称的变量或函数,则有时有必要解决歧义.

class SomeClass is a longhand way of referring to the class type SomeClass (technically, it's the elaborated type specifier). Usually, adding class is redundant, and the two are equivalent. But it's sometimes necessary to resolve the ambiguity, if there's a variable or function with the same name.

这篇关于“类"返回类型的关键字-C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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