我的班级有什么问题,我无法使用自定义讲师来实例化?

问题描述 投票:-1回答:1
#include <iostream>
#include <string>
using namespace std;

class Dog{
    private:
        int age;
        string name;

    public:
        Dog(int a, string x){ //constructor
            age = a;
            name = x;

        };
        string getName(){
            return name;
        };
        int getAge(){

            return age;
        };


};


int main(){

    Dog(10, "fid0") ben;

    cout<< ben.getName();

    return 0;
}

我无法使用自定义讲师实例化的班级有什么问题?我对cpp还是陌生的,无法弄清原因。我无法弄清楚为什么有时我的Dog对象有时被视为指针。资源将不胜感激

c++ class constructor
1个回答
1
投票

更改

© www.soinside.com 2019 - 2024. All rights reserved.