Невозможно преобразовать аргумент из const char[12] в char*
Задали задание в вузе по ООП.
Есть 3 класса.
CTime.h
#pragma once
#include <iostream>
using namespace std;
struct STime {
int hou, min, sec, dsec;
};
class CTime {
private:
double time; // время
public:
void Create(int hou, int min, int sec, int dsec); // создание времени
void Create(const STime& stime); // создание времени из STime
void Create(double dtime); // создание времени изdouble
void Create(char* dtime); // создание времени из “чччч:мм:сс,dd”
STime asstime(); // в STime
char* aschar();
int how();
int min();
int sec();
int dsec();
void Copy(const CTime& stime);
void addeq(const CTime& time);
CTime add(const CTime& time);
void diveq(const CTime& time);
CTime div(const CTime& time); // аналогthis -time
void print(); // выводнаэкран
void tostream(ostream& stream); // выводсебявпоток
void fromstream(istream& stream); // чтениевсебяизпотока
private:
double todouble(int hou, int min, int sec, int dsec); // hou, min, sec, dsec -> double
STime chartostime(char* str);// str -> STime
char* stimetochar(const STime& stime);// STime -> char*
};
CTime.cpp
#include "CTime.h"
#include <string>
double CTime::todouble(int hou, int min, int sec, int dsec)
{
double time = (sec + (min + hou * 60) * 60 + dsec / 100.) / 86400;
return time;
}
int charToInt(char* num)
{
return atoi(num); // переводит строку в число
}
STime CTime::chartostime(char* str)
{
int hou;
int min;
int sec;
int dsec;
char* buf = new char[2];
if (str[0] == '0') {
hou = charToInt(&str[1]);
}
else {
buf[0] = str[0];
buf[1] = str[1];
hou = charToInt(buf);
}
if (str[3] == '0') {
min = charToInt(&str[4]);
}
else {
buf[0] = str[3];
buf[1] = str[4];
min = charToInt(buf);
}
if (str[6] == '0') {
sec = charToInt(&str[7]);
}
else {
buf[0] = str[6];
buf[1] = str[7];
sec = charToInt(buf);
}
if (str[9] == '0') {
dsec = charToInt(&str[10]);
}
else {
buf[0] = str[9];
buf[1] = str[10];
dsec = charToInt(buf);
}
STime time;
time.hou = hou;
time.min = min;
time.sec = sec;
time.dsec = dsec;
delete buf;
return time;
}
char* CTime::stimetochar(const STime& stime)
{
string str = to_string(stime.hou) + ":" + to_string(stime.min);
str = str + ":";
str = str + to_string(stime.sec) + "." + to_string(stime.dsec);
return _strdup(str.c_str());
}
void CTime::Create(int hou, int min, int sec, int dsec)
{
time = todouble(hou, min, sec, dsec);
}
void CTime::Create(const STime& stime)
{
time = todouble(stime.hou, stime.min, stime.sec, stime.dsec);
}
void CTime::Create(double dtime)
{
time = dtime;
}
void CTime::Create(char* dtime)
{
STime stime = chartostime(dtime);
time = todouble(stime.hou, stime.min, stime.sec, stime.dsec);
}
STime CTime::asstime()
{
int dtime = time * 86400 * 100;
STime stime;
int buf;
buf = dtime % 100;
stime.dsec = buf;
dtime -= buf;
dtime /= 100;
buf = dtime % 60;
stime.sec = buf;
dtime -= buf;
dtime /= 60;
buf = dtime % 60;
stime.min = buf;
dtime -= buf;
dtime /= 60;
stime.hou = dtime;
return stime;
}
char* CTime::aschar()
{
return stimetochar(asstime());
}
int CTime::how()
{
return asstime().hou;
}
int CTime::min()
{
return asstime().min;
}
int CTime::sec()
{
return asstime().sec;
}
int CTime::dsec()
{
return asstime().dsec;
}
void CTime::Copy(const CTime& stime)
{
time = stime.time;
}
void CTime::addeq(const CTime& stime)
{
time = time + stime.time;
}
CTime CTime::add(const CTime& stime)
{
CTime ctime;
ctime.Create(time + stime.time);
return ctime;
}
void CTime::diveq(const CTime& stime)
{
time = time - stime.time;
}
CTime CTime::div(const CTime& stime)
{
CTime ctime;
ctime.Create(time - stime.time);
return ctime;
}
void CTime::print()
{
cout << aschar();
}
void CTime::tostream(ostream& stream)
{
stream << time;
}
void CTime::fromstream(istream& stream)
{
stream >> time;
}
Source.cpp
#include<clocale>
#include<iostream>
#include<fstream>
using namespace std;
#include"CTime.h"
int main()
{
setlocale(LC_CTYPE, "Russian");
CTime t1, t2, t3;
STime st1, st2;
t1.Create(5, 20, 30, 89);
cout << "t1 = "; t1.print(); cout << endl;
st1 = t1.asstime();
t2.Create(st1);
cout << "t2 = "; t2.print(); cout << endl;
t3.Create("02:24:57,87");
cout << "t3 = "; t3.print(); cout << endl;
st2 = t3.asstime();
char* stm = t3.aschar();
cout << stm << endl;
return 0;
}
Выводит ошибку
Ошибка C2664 "void CTime::Create(double)": невозможно преобразовать аргумент 1 из "const char [12]" в "char *"
Как это можно исправить?