I don't know where is the problem...
I wrote a Class named "Mystring", its head file like following:
#pragma once
class Mystring
{
private:
char* m_ptext;
int m_length;
public:
Mystring(const char*,int);
~Mystring(void);
Mystring(const Mystring&);
int messurelength(void);
}
The cpp file like follwing:
#include <iostream>
#include "Mystring.h"
Mystring::Mystring(const char* ptext="error",int length=5){
m_ptext=new char[length];
int count=0;
while(ptext[count]!='\0') count++;
if(length>=count) *m_ptext=*ptext;
else throw "error";
}
Mystring::Mystring(const Mystring& source){
delete[] m_ptext;
[u]char* m_ptext=new char[source.messurelength]; </u> //line 15
*m_ptext=*(source.m_ptext);
m_length=source.m_length;
}
Mystring::~Mystring(){
delete[] m_ptext;
}
int Mystring::messurelength(void){
int count=0;
while(m_ptext[count]!='\0') count++;
return count;
}
when I compiled it, a warning came out. it said:
"mystring.cpp(15) : errorC2662: 'Mystring::messurelength' : cannot convert 'this' pointer from 'const Mystring' to 'Mystring &' Conversion loses qualifiers"
I don't know where is the error, how to handle this?
thanks for any suggestions.
|