在现代编译器中使用C ++继承时如何在带参数和不带参数的函数之间进行区分

我正在学习C ++继承。以下是相同的程序。这里有NumberExNumber这两个类。 Number是基类。我在input的第二个ExNumber定义中遇到错误,该定义以setData为参数的int。我从老师那里知道该声明将在Turbo C ++编译器上运行。这在我的Visual Studio代码中不起作用。他为Turbo C ++授课。我需要有关如何在现代编译器中声明该定义的帮助。谢谢。我得到的错误是type name is not alowed。此错误是由于第二个输入函数中的setData引起的。预先感谢。

#include<iostream>
using namespace std;

class Number
{
    int no;
    public:
        void setData()
        {
            cout << "\nNo: ";
            cin >> no;
        }

        void setdata(int a)
        {
            no = a;
        }

        int getData()
        {
            return no;
        }

        void display()
        {
            cout << "\nRoll  No:" << no;

        }
};

class  ExNumber : Number
{
    public:
        void input()
        {
            setData();
        }

        void input (int)
        {
            setData( int);
        }

        void output()
        {
            display();
        }

        void table();
        int isPrime();
};

void ExNumber :: table()
{
    int i = 1,n = getData();
    cout << "\nTable\n";
    while(i <= 10)
    {
        cout << "   " << n*i;
        i++;
    }
}

int ExNumber :: isPrime()
{
    int i = 2,n = getData();
    while(i < n)
    {
        if( n % i == 0)
            break;
        i++;
    }
    return (i == n) ;
}

int main()
{
    ExNumber p;
    p.input(23);
    p.output();
    p.table();
    ExNumber q;
    q.input();
    q.output();
    if(q.isPrime() == 0)
        cout << "\nNot";
    cout << " Prime";
    return 0;
}
fancykee 回答:在现代编译器中使用C ++继承时如何在带参数和不带参数的函数之间进行区分

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/1447163.html

大家都在问