Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / June 2005

Tip: Looking for answers? Try searching our database.

error LNK2020

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jazz - 13 Jun 2005 21:22 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.