- 论坛徽章:
- 0
|
#include<iostream>
using namespace std;
#include "string.h"
class book
{
public:
book();
book(char*,char*,char*,float);
const string& Gettitle()const{return title;}
const string& GetAuthor()const{return author;}
const string& GetNumber()const{return number;}
float GetPrice()const{return price;}
void Settitle(const string&stitle){title=stitle;}
void SetNumber(const string&snumber){number=snumber;}
void SetAuthor(const string&sauthor){author=sauthor;}
void SetPrice(float sprice){price=sprice;}
void SetTotal(const string&T,const string&N,const string&A,float P )
{
title=T;
number=N;
author=A;
price=P;
}
private:
string title;
string author;
string number;
float price;
};
book::book():title(""),author(""),number(""),price(0)
{
}
book::book(char*title,char*Author,char*Number,float Price):title(title),author(Author),number(Number),price(Price)
{
}
int main()
{
book love("love","Jacky","001","34.1");
cout<<"书名:"<<love.Gettitle()<<"作者:"<<love.GetAuthor()<<"编号:"<<love.GetNumber()<<"价格:"<<love.GetPrice()<<endl;
return 0;
}
以下是报错信息:
--------------------Configuration: dmcy - Win32 Debug--------------------
Compiling...
dmcy.cpp
C:\test\dmcy\dmcy.cpp(42) : error C2664: '__thiscall book::book(char *,char *,char *,float)' : cannot convert parameter 4 from 'char [5]' to 'float'
There is no context in which this conversion is possible
C:\test\dmcy\dmcy.cpp(43) : error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'const class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or there is no acceptable conversion
)
执行 cl.exe 时出错.
dmcy.exe - 1 error(s), 0 warning(s)
|
|