注册 登录
编程论坛 C++教室

求助

me100422 发布于 2012-12-15 18:48, 258 次点击

#include<iostream>
using namespace std;
class Name
{
public:
    char name;
    Name(char b):name(b){}

};
class Dog:public Name
{
public:
    dog(int n,char c):Name(c),weight(n){}
    void getWeight(){cout<<weight<<" "<<name;}
private:
    int weight;
};
int main()
{
    Dog a(80,'d');
    a.getWeight();
    return 0;
}

--------------------Configuration: dxc6 - Win32 Debug--------------------
Compiling...
dxc6.cpp
H:\dxc6\dxc6.cpp(14) : error C2065: 'c' : undeclared identifier
H:\dxc6\dxc6.cpp(14) : error C2057: expected constant expression
H:\dxc6\dxc6.cpp(14) : error C2656: 'dog' : function not allowed as a bit field
H:\dxc6\dxc6.cpp(14) : error C2061: syntax error : identifier 'n'
H:\dxc6\dxc6.cpp(14) : error C2143: syntax error : missing ';' before '{'
H:\dxc6\dxc6.cpp(14) : error C2334: unexpected token(s) preceding '{'; skipping apparent function body
H:\dxc6\dxc6.cpp(26) : fatal error C1004: unexpected end of file found
执行 cl.exe 时出错.

dxc6.obj - 1 error(s), 0 warning(s)
2 回复
#2
lz10919149992012-12-15 18:54
Dog(int n,char c):Name(c),weight(n){}
#3
liao254283012012-12-17 01:57
楼主大小写都乱写,这样怎能不出错
1