c++ - 实例化类时 加不加括号问题
ringa_lee
ringa_lee 2017-04-17 15:04:11
0
1
638

实例化类时 会出现两种情况 如下 :

  1. 有括号 无法使用 最后一个注释内的语句

  2. 无括号 则能用

error: request for member 'Person:: func' in 'man', which is of non-class type 'Man()'

#include <iostream>

using namespace std;

class Person
{
public:
    void func()
    {
        cout << "base func" << endl;
    }
};

class Man: public Person
{
public:
    void func()
    {
        cout << "deperive func" << endl;
    }
};

int main()
{
    Man man();

    cout << "man.Person::func()显示调用的输出是:";
    
    /**********************************************/
    //man.Person::func();   
    /*********************************************/
    
    system ( "pause" );
}

有无括号的区别是什么 网上我并没有找到我认为合理的答案

ringa_lee
ringa_lee

ringa_lee

reply all(1)
迷茫

Man man();
is considered a function declaration...

A function named man has a return type of Man

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template