关于const的有关问题!(以及strcpy()在C++中的用法)
关于const的问题!(以及strcpy()在C++中的用法)
在类的声明中有:
class Message
{
public:
Message(const char* pStr, const char* key);
Message(const char* pStr);
Message();
void encryptMessage();
void decryptMessage();
const char* getUnMessage() const;
const char* getEnMessage() const;
void getMessage();
void getKey();
~Message();
private:
char* pUnMessage;
char* pEnMessage;
char* pKey;
};
类的实现中有:Message::Message()
{}
//Constructor
Message::Message(const char* pStr, const char* key){
int i, j;
pUnMessage = new char[ strlen(pStr) + 1 ];
strcpy(pUnMessage, pStr);
cout < <*pUnMessage < <endl;
pEnMessage = new char[ strlen(pStr) + 1 ];
strcpy(pEnMessage, pStr);
pKey = new char[ strlen(pStr) + 1 ];
strcpy(pKey, pStr);
for(i = 0, j = 0; i < (int) strlen(pStr), j < (int) strlen(pStr); i++, j++)
{
if(key[j] && pKey[i])
{
pKey[i] = key[j];
}
else if(key[j] == '\0 ')
{
j = -1;
i--;
}
else
break;
}
}
//Constructor for only the message, not the key
Message::Message(const char* pStr)
{
pUnMessage = new char[ strlen(pStr) + 1 ];
strcpy(pUnMessage, pStr);
pEnMessage = new char[ strlen(pStr) + 1 ];
strcpy(pEnMessage, pStr);
}
我想问以下怎么能把警告消除??
还有就是这个类的实现是什么意思?
------解决方案--------------------
什么警告??
------解决方案--------------------
什么警告?拿出来看看。。。
无非是指针未初始化什么的
------解决方案--------------------
试试这个,你可以把数字改成你需要的。
#define warning(disable:1647)
------解决方案--------------------
“C++速成版”是什么东西?VC express?
当没看见那个warning即可。
在类的声明中有:
class Message
{
public:
Message(const char* pStr, const char* key);
Message(const char* pStr);
Message();
void encryptMessage();
void decryptMessage();
const char* getUnMessage() const;
const char* getEnMessage() const;
void getMessage();
void getKey();
~Message();
private:
char* pUnMessage;
char* pEnMessage;
char* pKey;
};
类的实现中有:Message::Message()
{}
//Constructor
Message::Message(const char* pStr, const char* key){
int i, j;
pUnMessage = new char[ strlen(pStr) + 1 ];
strcpy(pUnMessage, pStr);
cout < <*pUnMessage < <endl;
pEnMessage = new char[ strlen(pStr) + 1 ];
strcpy(pEnMessage, pStr);
pKey = new char[ strlen(pStr) + 1 ];
strcpy(pKey, pStr);
for(i = 0, j = 0; i < (int) strlen(pStr), j < (int) strlen(pStr); i++, j++)
{
if(key[j] && pKey[i])
{
pKey[i] = key[j];
}
else if(key[j] == '\0 ')
{
j = -1;
i--;
}
else
break;
}
}
//Constructor for only the message, not the key
Message::Message(const char* pStr)
{
pUnMessage = new char[ strlen(pStr) + 1 ];
strcpy(pUnMessage, pStr);
pEnMessage = new char[ strlen(pStr) + 1 ];
strcpy(pEnMessage, pStr);
}
我想问以下怎么能把警告消除??
还有就是这个类的实现是什么意思?
------解决方案--------------------
什么警告??
------解决方案--------------------
什么警告?拿出来看看。。。
无非是指针未初始化什么的
------解决方案--------------------
试试这个,你可以把数字改成你需要的。
#define warning(disable:1647)
------解决方案--------------------
“C++速成版”是什么东西?VC express?
当没看见那个warning即可。