下列程序编译时有语法错误的语句是()
#include
发布于 2022-03-03 17:36:40
下列程序编译时有语法错误的语句是() #include<iostream>
#include<string>
using namespace std
class Pet {
string name
public:
Pet(string p=" ") { name = p }
string getName() const { return name }
virtual void call() const=0
}
class Dog : public Pet{
public:
Dog(string n) : Pet(n) {}
void call() const { cout<< "##" << " " }
}
class Cat : public Pet{
public:
Cat(string n) : Pet(n) {}
void call() const { cout << "**" }
}
void f(Pet *p) {
p->call()
}
int main() {
Pet pet0("#") //(1)
Dog pet1("*") //(2)
Cat pet2("$") //(3)
f(&pet1) //(4)
f(&pet2) //(5)
return 0
}
登录后免费查看答案
发布于 2022-03-03 17:36:40
下列程序编译时有语法错误的语句是()
#include<iostream> #include<string> using namespace std class Pet { string name public: Pet(string p=" ") { name = p } string getName() const { return name } virtual void call() const=0 } class Dog : public Pet{ public: Dog(string n) : Pet(n) {} void call() const { cout<< "##" << " " } } class Cat : public Pet{ public: Cat(string n) : Pet(n) {} void call() const { cout << "**" } } void f(Pet *p) { p->call() } int main() { Pet pet0("#") //(1) Dog pet1("*") //(2) Cat pet2("$") //(3) f(&pet1) //(4) f(&pet2) //(5) return 0 }
登录后免费查看答案
关注者
0
被浏览
38