如何解决在现代编译器中使用C ++继承时如何在带参数和不带参数的函数之间进行区分
我正在学习C ++继承。以下是相同的程序。这里有Number
和Exnumber
这两个类。 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;
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。