使用gcc时出现这undefined reference to `String::String(char const*)'。是不是G++使用不正确??
1个回答
展开全部
String(const String &another ); //拷贝构造函数
~String(); //析构函数
String& operator =(const String &rhs); // 赋值函数private:
char *m_data; //用于保存字符串};#endif// String.cpp
//-------------------------------------------------------
#include "Sting.h"
#include <iostream>
String::String(const char* str){if(str == NULL){m_data = new char[1];
m_data[0] = '\0';}else{m_data = new char[strlen(str) + 1];
strcpy(m_data, str);}}String::String(const String &another){m_data = new char[strlen(another.m_data) + 1];
strcpy(m_data, str);}String::~String(){delete []m_data;}String& String::operator= (const String &rhs){if( this == &rhs )
return this;
delete []m_data;
m_data = new char[strlen(rhs) + 1];
strcpy(m_data, str);
return *this;}// 执行文件
//------------------------------------------------------------
#ifndef NULL
#define NULL 0#endif#include "String.h"
#include <iostream>
int main(void){
String str("asdasda");return 1;}还是没通过[root@localhost 桌面]# g++ main.C -o main
/tmp/ccZLDigD.o: In function `main':
main.C:(.text+0x1a): undefined reference to `String::String(char const*)'
main.C:(.text+0x2b): undefined reference to `String::~String()'
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询