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::operator =(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::operator =(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::operator ==(const char* str)
{
return strcmp(str, _string)?false:true;
}
inline bool MyString::operator ==(const MyString& rhs)
{
return strcmp(_string, rhs._string)?false:true;
}
inline char& MyString::operator [](int i)
{
return _string[i];
}
Console.cpp
#include "MyString.h"
#using <mscorlib.dll>
using namespace System;
int _tmain()
{
MyString str2("abcdefg");
return 0;
}
Hendrik Schober - 14 Jun 2005 10:58 GMT
> Hello,
> I am using VS.net 2003 and trying to build a very simple console c++
[quoted text clipped - 10 lines]
> Jazz
> [code snippet]
If you want a function to get inlined, the
compiler needs to see it everywhere it is
used. If you define 'inline' functions within
a cpp file, the compiler only sees them
within this cpp file. Other cpp files, that
only see the header, won't see the definition.
They thus assume the function to be defined
somewhere else -- which it isn't in this case.
In short: Either don't make your functions
inline or move their definition into the
header.
HTH,
Schobi

Signature
SpamTrap@gmx.de is never read
I'm Schobi at suespammers dot org
"Coming back to where you started is not the same as never leaving"
Terry Pratchett
Jazz - 14 Jun 2005 13:32 GMT
Schobi,
This works. Thanks again for the help.
Jazz
> > Hello,
> > I am using VS.net 2003 and trying to build a very simple console c++
[quoted text clipped - 26 lines]
>
> Schobi