The code below generates LNK2019. I have no idea why that is happening. Please let me know so I can

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
File main.cpp
<pre class="prettyprint" style=" #include "Test.h"
#include <memory>
#include <iostream>

int main()
{
try
{
std::unique_ptr<A> uA(new A(1, "Test"));

throw A::Exception(id2, *uA.get());
}
catch( A::Exception& a )
{
std::cout << a.GetName() << std::endl;
return -1;
}
return 0;
}[/code]
<br/>
File test.h
<pre class="prettyprint" style=" namespace
{
enum n_TableID { id1, id2, id3 };
}

class A
{
int i;
char Name[32];

public:
A(int, char*);
const char* GetName() const { return Name; }

class Exception
{
int i;
char Name[32];
public:
Exception(n_TableID, const A&);
const char* GetName() { return Name; }
};
};[/code]
<br/>
File test.cpp
<pre class="prettyprint" style=" #include <iostream>
#include "Test.h"

A::A(int k, char* pName) : i(k)
{
strcpy_s(Name, 32, pName);
}

A::Exception::Exception(n_TableID id, const A& a) : i(id)
{
strcpy_s(Name, a.GetName());
}[/code]
<br/>
<br/>

Error<span class="x_x_x_Apple-tab-span" style="white-space:pre 1<span class="x_x_x_Apple-tab-span" style="white-space:pre
error LNK2019: unresolved external symbol "public: __thiscall A::Exception::Exception(enum `anonymous namespace::n_TableID,class A const &)" (??0Exception@A@@QAE@W4n_TableID@?A0x7dd2f92a@@ABV1@@Z) referenced in function _main<span class="x_x_x_Apple-tab-span" style="white-space:pre
C:UsersABCDocumentsVisual Studio 2010ProjectsTablesConsole Test 1main.obj<br/>
<br/>
<br/>

View the full article
 
Back
Top