程序调试不通,c++图书卡片类
#include <iostream.h>
#include <string.h>
class Card
{
public:
//char * t,* name;
//int num;
void Card(char * t,char * name,int num);
void Show();
private:
char title[80];
char author[40];
int number;
};
void Card::Card(char*t,char*name,int num)
{
strncpy(title,t,sizeof(title));
title[sizeof(title)/sizeof(*title)-1]= '\0 ';
strncpy(author,name,sizeof(author));
author[sizeof(author)/sizeof(*author)-1]= '\0 ';
number=num;
}
void Card::Show()
{
cout < < "\nTitle: " < <title < <endl;
cout < < "Author: " < <author < <endl;
cout < < "Number on hand: " < <number < <endl;
}
void main()
{
Card book1( "Dune ", "Frank Herbert ",2);
Card book2( "The Foundation Trilogy ", "Isaac Asimov ",2);
Card book3( "The Rainbow ", "D.H.lawrence ",1);
book1.Show();
book2.Show();
book3.Show();
}
错误提示:
--------------------Configuration: c++31 - Win32 Debug--------------------
Compiling...
c++31.cpp
E:\C语言上机调试\c++31.cpp(8) : error C2380: type(s) preceding 'Card ' (constructor with return type, or illegal redefinition of current class-name?)
E:\C语言上机调试\c++31.cpp(16) : error C2533: 'Card::Card ' : constructors not allowed a return type
E:\C语言上机调试\c++31.cpp(31) : error C2264: 'Card::Card ' : error in function definition or declaration; function not called
E:\C语言上机调试\c++31.cpp(32) : error C2264: 'Card::Card ' : error in function definition or declaration; function not called
E:\C语言上机调试\c++31.cpp(33) : error C2264: 'Card::Card ' : error in function definition or declaration; function not called
Error executing cl.exe.
c++31.obj - 5 error(s), 0 warning(s)
请大家帮忙!
[解决办法]
void Card::Card(char*t,char*name,int num)
=========================================
构造函数没有返回类型.
class Card
{
public:
Card(char*t,char*name,int num);
.............................
};
Card::Card(char*t,char*name,int num)
{
.................
}