为什么该类对象声明起作用? [英] Why does this class object declaration work?

查看:85
本文介绍了为什么该类对象声明起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一堂课

class Test{
  public:
    int x;
    Test(const Test& obj){x=obj.x;}
};

为什么

Test object_name(Test random_name);

运行,是否不需要另一个对象作为参数? 像Test random_name(Test another_random(...))一样,使它成为声明对象的永无止境的方式吗?

run and does not need another object as a parameter?. .Something like Test random_name(Test another_random(...)), making it a never ending way of declaring the object?

推荐答案

此行:

Test object_name(Test random_name);

声明一个名为object_name的函数,该函数将Test作为参数并返回Test.它没有声明对象.在另一个函数中声明这样的函数是完全合法的,它只是隐式地extern.

declares a function called object_name that takes a Test as a paramter and returns a Test. It does not declare an object. It is perfectly legal to declare a function like this inside another function, it's just implicitly extern.

这篇关于为什么该类对象声明起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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