#pragma once
# include <iostream>
# include <string>
# include <cstring>
using namespace std;
const int err=404;
class longMath{
protected:
char* str;
int size;
protected:
//void create(int len);
public:
inline longMath();
inline longMath(longMath &a);
inline longMath(char* s);
inline longMath(string &s);
~longMath(){delete [] str;}
void print();
};
//-------------------------------------------------------------//
longMath::longMath(){size=0;}
longMath::longMath(longMath &a){
str = new char [a.size];
strncpy(str,a.str,a.size);
size= a.size;
}
longMath::longMath(char* s){
size = (sizeof s)/(sizeof s[0]);
str = new char [size+1];
strncpy_s(str,size+1,s,size);
}
void longMath::print(){
for (int i=0;i<size;i++){
cout<<*(str+i);
}
cout<<endl;
}
longMath::longMath(string &s){
str = new char [s.length()];
for (int i=0;i<size;i++){
*(str+i)=s[i];
}
size = s.length();
}
longMath longMath::operator= (const longMath &a){//оператор присвоения
if (this==&a) return *this;
delete [] str;
str = new char [a.size];
strncpy(str,a.str,a.size);
size = a.size;
return *this;
}
//----------additional function--------------------//
int switcher(char &c){
switch (c){
case '1': return 1; break;
case '2': return 2; break;
case '3': return 3; break;
case '4': return 4; break;
case '5': return 5; break;
case '6': return 6; break;
case '7': return 7; break;
case '8': return 8; break;
case '9': return 9; break;
case '0': return 0; break;
default: return err;
}
}
还有另一个主文件
# include <iostream>
# include "longMath.h"
using namespace std;
int main(){
char* s("regw");
longMath h,n(s);
n.print();
system("PAUSE");
return 0;
}
该程序不想编译,它返回异常0x0f8657aa (msvcr100d.dll)
请帮帮我。程序似乎不太复杂。构造函数有问题,初始化为char*
.