G
Guest
Hello,
I am using VS.net 2003 and trying to build a very simple console c++
application. But got the
Console error LNK2020: unresolved token (0A00000D) MyString.__dtor
Console fatal error LNK1120: 1 unresolved externals
I have 3 files, one is Console.cpp and the other two are MyString.h and
MyString.cpp.
Anyone Can help me out?
Thanks a lot.
Jazz
MyString.h
#include<iostream>
#ifndef MYSTRING_H
#define MYSTRING_H
class MyString
{
public:
MyString(const char* =0);
MyString(const MyString&);
~MyString();
MyString& operator=(const MyString&);
MyString& operator=(const char*);
bool operator==(const MyString&);
bool operator==(const char*);
char& operator[](int);
int size() { return _size;};
char* c_str() { return _string;};
private:
int _size;
char* _string;
};
#endif
MyString.cpp
#include "MyString.h"
inline MyString::MyString(const char* str)
{
if(!str)
{
_size = 0;
_string = 0;
}
else
{
_size = strlen(str);
_string = new char[_size+1];
strcpy(_string, str);
}
}
inline MyString::MyString(const MyString& rhs)
{
_size = rhs._size;
if(_size ==0)
{
_string = 0;
}
else
{
_string = new char[_size+1];
strcpy(_string, rhs._string);
}
}
inline MyString::~MyString()
{
delete[] _string;
}
inline MyString& MyString:perator =(const char* str)
{
if(_size!=0)
delete[] _string;
if(str)
{
_size = strlen(str);
_string = new char[_size+1];
strcpy(_string, str);
}
else
{
_size=0;
_string = 0;
}
return *this;
}
inline MyString& MyString:perator =(const MyString& rhs)
{
if(this==&rhs)
return *this;
if(_size!=0)
delete[] _string;
if(rhs._size>0)
{
_size = rhs._size;
_string = new char[_size+1];
strcpy(_string, rhs._string);
}
else
{
_size=0;
_string = 0;
}
return *this;
}
inline bool MyString:perator ==(const char* str)
{
return strcmp(str, _string)?false:true;
}
inline bool MyString:perator ==(const MyString& rhs)
{
return strcmp(_string, rhs._string)?false:true;
}
inline char& MyString:perator [](int i)
{
return _string;
}
Console.cpp
#include "MyString.h"
#using <mscorlib.dll>
using namespace System;
int _tmain()
{
MyString str2("abcdefg");
return 0;
}
I am using VS.net 2003 and trying to build a very simple console c++
application. But got the
Console error LNK2020: unresolved token (0A00000D) MyString.__dtor
Console fatal error LNK1120: 1 unresolved externals
I have 3 files, one is Console.cpp and the other two are MyString.h and
MyString.cpp.
Anyone Can help me out?
Thanks a lot.
Jazz
MyString.h
#include<iostream>
#ifndef MYSTRING_H
#define MYSTRING_H
class MyString
{
public:
MyString(const char* =0);
MyString(const MyString&);
~MyString();
MyString& operator=(const MyString&);
MyString& operator=(const char*);
bool operator==(const MyString&);
bool operator==(const char*);
char& operator[](int);
int size() { return _size;};
char* c_str() { return _string;};
private:
int _size;
char* _string;
};
#endif
MyString.cpp
#include "MyString.h"
inline MyString::MyString(const char* str)
{
if(!str)
{
_size = 0;
_string = 0;
}
else
{
_size = strlen(str);
_string = new char[_size+1];
strcpy(_string, str);
}
}
inline MyString::MyString(const MyString& rhs)
{
_size = rhs._size;
if(_size ==0)
{
_string = 0;
}
else
{
_string = new char[_size+1];
strcpy(_string, rhs._string);
}
}
inline MyString::~MyString()
{
delete[] _string;
}
inline MyString& MyString:perator =(const char* str)
{
if(_size!=0)
delete[] _string;
if(str)
{
_size = strlen(str);
_string = new char[_size+1];
strcpy(_string, str);
}
else
{
_size=0;
_string = 0;
}
return *this;
}
inline MyString& MyString:perator =(const MyString& rhs)
{
if(this==&rhs)
return *this;
if(_size!=0)
delete[] _string;
if(rhs._size>0)
{
_size = rhs._size;
_string = new char[_size+1];
strcpy(_string, rhs._string);
}
else
{
_size=0;
_string = 0;
}
return *this;
}
inline bool MyString:perator ==(const char* str)
{
return strcmp(str, _string)?false:true;
}
inline bool MyString:perator ==(const MyString& rhs)
{
return strcmp(_string, rhs._string)?false:true;
}
inline char& MyString:perator [](int i)
{
return _string;
}
Console.cpp
#include "MyString.h"
#using <mscorlib.dll>
using namespace System;
int _tmain()
{
MyString str2("abcdefg");
return 0;
}