Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

#ActualL. Spiro

Posted 22 October 2012 - 06:23 PM

EDIT: Btw, I have no idea what's going on but the <code> feature on the forums won't work right for me... At least it's showing my code all comes out in one, mangled line in my above post...

You are using [source] tags.  You should be using [code] tags.


1) Global operators and linker errors ::

Why does it cause a linker error to prototype a global operator in a header file then implement it in a source file, like so::

// point.h ::
Point operator +( const Point& p1, const Point& p2 );
Point operator -( const Point& p1, const Point& p2 );

// point.cpp ::
Point operator +( const Point& p1, const Point& p2 ) {
	Point result = p1;
	return ( result += p2 );
}

Point operator -( const Point& p1, const Point& p2 ) {
	Point result = p1;
	return ( result -= p2 );
}


Error 1 error LNK2019: unresolved external symbol "struct ATCFramework::Drawing::Point __cdecl ATCFramework::Drawing::operator+(struct ATCFramework::Drawing::Point const &,struct ATCFramework::Drawing::Point const &)" (??HDrawing@ATCFramework@@YA?AUPoint@01@ABU201@0@Z) referenced in function _wmain C:\Users\ATC\Documents\Visual Studio 2012\Projects\ATCWARE\src\ConsoleTest\main.obj ConsoleTest

(NOTE:: I also get LNK1120, unresolved external symbols, of course...)

But if I just move the implementation of the operators into the header file it compiles and runs fine. What the deal?? Posted Image

You did not fully qualify the definition of the operator in the .CPP file.
It should be:
ATCFramework::Drawing::Point ATCFramework::Drawing::operator + ( const Point & p1, const Point & p2 ) {
	Point result = p1;
	return ( result += p2 );
}


L. Spiro

#3L. Spiro

Posted 22 October 2012 - 06:22 PM

EDIT: Btw, I have no idea what's going on but the <code> feature on the forums won't work right for me... At least it's showing my code all comes out in one, mangled line in my above post...

You are using [source] tags.  You should be using [code] tags.


1) Global operators and linker errors ::

Why does it cause a linker error to prototype a global operator in a header file then implement it in a source file, like so::

// point.h ::
Point operator +( const Point& p1, const Point& p2 );
Point operator -( const Point& p1, const Point& p2 );

// point.cpp ::
Point operator +( const Point& p1, const Point& p2 ) {
	Point result = p1;
	return ( result += p2 );
}

Point operator -( const Point& p1, const Point& p2 ) {
	Point result = p1;
	return ( result -= p2 );
}


Error 1 error LNK2019: unresolved external symbol "struct ATCFramework::Drawing::Point __cdecl ATCFramework::Drawing::operator+(struct ATCFramework::Drawing::Point const &,struct ATCFramework::Drawing::Point const &)" (??HDrawing@ATCFramework@@YA?AUPoint@01@ABU201@0@Z) referenced in function _wmain C:\Users\ATC\Documents\Visual Studio 2012\Projects\ATCWARE\src\ConsoleTest\main.obj ConsoleTest

(NOTE:: I also get LNK1120, unresolved external symbols, of course...)

But if I just move the implementation of the operators into the header file it compiles and runs fine. What the deal?? Posted Image

You did not fully qualify the definition of the operator in the .CPP file.
It should be:
ATCFramework::Drawing::Point ATCFramework::Drawing::operator + ( const ATCFramework::Drawing::Point & p1, const ATCFramework::Drawing::Point & p2 ) {
	Point result = p1;
	return ( result += p2 );
}


L. Spiro

#2L. Spiro

Posted 22 October 2012 - 06:22 PM

EDIT: Btw, I have no idea what's going on but the <code> feature on the forums won't work right for me... At least it's showing my code all comes out in one, mangled line in my above post...

You are using [source] tags.  You should be using [code] tags.


1) Global operators and linker errors ::

Why does it cause a linker error to prototype a global operator in a header file then implement it in a source file, like so::

// point.h ::
Point operator +( const Point& p1, const Point& p2 );
Point operator -( const Point& p1, const Point& p2 );

// point.cpp ::
Point operator +( const Point& p1, const Point& p2 ) {
	Point result = p1;
	return ( result += p2 );
}

Point operator -( const Point& p1, const Point& p2 ) {
	Point result = p1;
	return ( result -= p2 );
}


Error 1 error LNK2019: unresolved external symbol "struct ATCFramework::Drawing::Point __cdecl ATCFramework::Drawing::operator+(struct ATCFramework::Drawing::Point const &,struct ATCFramework::Drawing::Point const &)" (??HDrawing@ATCFramework@@YA?AUPoint@01@ABU201@0@Z) referenced in function _wmain C:\Users\ATC\Documents\Visual Studio 2012\Projects\ATCWARE\src\ConsoleTest\main.obj ConsoleTest

(NOTE:: I also get LNK1120, unresolved external symbols, of course...)

But if I just move the implementation of the operators into the header file it compiles and runs fine. What the deal?? Posted Image

You did not fully qualify the definition of the structure in the .CPP file.
It should be:
ATCFramework::Drawing::Point ATCFramework::Drawing::operator + ( const ATCFramework::Drawing::Point & p1, const ATCFramework::Drawing::Point & p2 ) {
	Point result = p1;
	return ( result += p2 );
}


L. Spiro

#1L. Spiro

Posted 22 October 2012 - 06:21 PM

EDIT: Btw, I have no idea what's going on but the <code> feature on the forums won't work right for me... At least it's showing my code all comes out in one, mangled line in my above post...

You are using [source] tags.  You should be using
tags.


[quote name='ATC' timestamp='1350845223' post='4992515']
[b]1)[/b] [u][i]Global operators and linker errors ::[/i][/u]

Why does it cause a linker error to prototype a global operator in a header file then implement it in a source file, like so::

[code]
// point.h ::
Point operator +( const Point& p1, const Point& p2 );
Point operator -( const Point& p1, const Point& p2 );

// point.cpp ::
Point operator +( const Point& p1, const Point& p2 ) {
	Point result = p1;
	return ( result += p2 );
}

Point operator -( const Point& p1, const Point& p2 ) {
	Point result = p1;
	return ( result -= p2 );
}[/code]


[i]Error 1 error LNK2019: unresolved external symbol "struct ATCFramework::Drawing::Point __cdecl ATCFramework::Drawing::operator+(struct ATCFramework::Drawing::Point const &,struct ATCFramework::Drawing::Point const &)" (??HDrawing@ATCFramework@@YA?AUPoint@01@ABU201@0@Z) referenced in function _wmain C:\Users\ATC\Documents\Visual Studio 2012\Projects\ATCWARE\src\ConsoleTest\main.obj ConsoleTest[/i]

(NOTE:: I also get LNK1120, unresolved external symbols, of course...)

But if I just move the implementation of the operators into the header file it compiles and runs fine. What the deal?? [img]http://public.gamedev.net//public/style_emoticons/default/blink.png[/img]
[/quote]
You did not fully qualify the definition of the structure in the .CPP file.
It should be:[code]
ATCFramework::Drawing::Point ATCFramework::Drawing::operator + ( const ATCFramework::Drawing::Point & p1, const ATCFramework::Drawing::Point & p2 ) {
    Point result = p1;
    return ( result += p2 );
}


L. Spiro

PARTNERS