难住了!菜鸟被男住了。忽忽!

来源:百度知道 编辑:UC知道 时间:2024/06/20 16:53:31
#include <iostream.h>

public class A
{
public A()
{
cout<<"A"<<endl;
}

public A(int foo)
{
cout<<"A="<<foo<<endl;
}
};

public class B:public A
{
public B(int foo)
{
cout<<"B="<<foo<<endl;
}
};

void main()
{
B Instant(42);
}

有好多错误!晕死我了。
ompiling...
Cpp1.cpp
E:\study\c++\aa\Cpp1.cpp(3) : error C2143: syntax error : missing ';' before 'public'
E:\study\c++\aa\Cpp1.cpp(4) : error C2143: syntax error : missing ';' before '{'
E:\study\c++\aa\Cpp1.cpp(4) : error C2447: missing function header (old-style formal list?)
E:\study\c++\aa\Cpp1.cpp(16) : error C2143: syntax error : missing ';' before 'public'
E:

1.public class A是什么意思?A如果是基类就写public A
2.类中如果你想声明公有成员就写public: 如
public:
A(){cout<<"A"<<endl;}
3.public class B:public A错,如果你想定义B是A的公有继承就写 class B:public A
4.类B中没有Instant函数,无法调用
另外,如果B是A的公有继承,应该在其构造函数里显示对A构造.建议你先将教材里的函数格式弄弄熟,基本格式搞懂.

另外,二楼的大虾说错了,定义类时}后面应该加分号.

你有见过}后面加;的么?
public class B:public A
{
public B(int foo)
{
cout<<"B="<<foo<<endl;
}
}; <---

B Instant(42); 就不对啊
你前面根本没有定义Instant函数啊,没办法调用~

兄弟 你“;” 加太多了 呵呵