unexpected class 新手求助
这是小甲鱼上课用的一段代码,但是总是提示我unexpected class'Dog'#include <iostream>
#include <string>
class Pet
{
public:
Pet(std::string theName);
~Pet();
static int getCount();
protected:
std::string name;
private:
static int count;
}
class Dog:public Pet
{
public:
Dog(std::string theName);
};
class Cat:public Pet
{
public:
Dog(std::string theName);
};
int Pet::count=0;
Pet::Pet(std::string theName)
{
name=theName;
}
Pet::~Pet()
{
count--;
std::cout<<name<<"挂掉了\n";
}
int Pet::getCount()
{
return count;
}
Dog::Dog(std::string theName):Pet(theName)
{
}
Cat::Cat(std::string theName):Pet(theName)
{
}
int main()
{
Dog dog("Tom");
Cat cat("Terry");
std::cout<<"\n已经诞生了"<<Pet::getCount()<<"zhichongwu\n\n";
{
Dog dog2("tom 2");
Cat cat2("jerry 2");
std::cout<<"\n现在呢,已经诞生了"<<Pet::getCount()<<"只宠物\n\n";
}
std::cout<<"\nAnd you're back to"<<Pet::getCount()<<"Pets!\n\n";
return 0;
}
我用的vc++6.0 class Cat:public Pet
{
public:
Dog(std::string theName);//应该是Cat(std::string theName);
};
这小雨有点大 发表于 2016-9-20 21:21
class Cat:public Pet
{
public:
这个已经改了 但是还是不对 不知道为什么 pet 类结束少一个“;”,再把上次跟你说的dog改成cat,我用的vs2015 运行成功,还有问题的话你最好把错误的提示截图一下 这个就是我运行的
#include <iostream>
#include <string>
class Pet
{
public:
Pet(std::string theName);
~Pet();
static int getCount();
protected:
std::string name;
private:
static int count;
};
class Dog:public Pet
{
public:
Dog(std::string theName);
};
class Cat:public Pet
{
public:
Cat(std::string theName);
};
int Pet::count=0;
Pet::Pet(std::string theName)
{
name=theName;
}
Pet::~Pet()
{
count--;
std::cout<<name<<"挂掉了\n";
}
int Pet::getCount()
{
return count;
}
Dog::Dog(std::string theName):Pet(theName)
{
}
Cat::Cat(std::string theName):Pet(theName)
{
}
int main()
{
Dog dog("Tom");
Cat cat("Terry");
std::cout<<"\n已经诞生了"<<Pet::getCount()<<"zhichongwu\n\n";
{
Dog dog2("tom 2");
Cat cat2("jerry 2");
std::cout<<"\n现在呢,已经诞生了"<<Pet::getCount()<<"只宠物\n\n";
}
std::cout<<"\nAnd you're back to"<<Pet::getCount()<<"Pets!\n\n";
return 0;
}
页:
[1]