Hi there,

I have a simple problem.

I have a namespace with a couple of classes declared in a header file. The classes have functions but no body.

When I include the header file and try to call a function, i get the error unresolved external symbol referenced in function _main.

//headerfile
// forward declaration
namespace Test
{
	class a;
	class b;
}
namespace Test
{
	class a
	{
	public:
	   void afunction ();
	};
	class b
	{
	public:
	   void bfunction ();
	};
}
/// the main file
#include <iostream>
#include "headerfile.h"
using namespace std;

int main ()
{
	Test::a* a = new Test::a();
	a->afunction();
}

you have not written the implementation code for the functions in those two classes.

Thanx a lot. I was just experimenting, and thought it would not be necessary. Just a simple declaration should be enough. Learned something new today.

By the way the implementation was simple. Just made a cpp file with a cout message in the function.

namespace Test
{
	   void a::afunction ()
	  {
		cout<<"this works"<<endl;
	  }
}

it would have been even easier had you used inline code

namespace Test
{
	class a
	{
	public:
	   void afunction () {cout << "this workd\n";}
	};

I'm not a big fan of inline code. Just the way I was tought. All functions no matter even if the're one liners are declared in cpp. Just my personal preference :).

This question has already been answered. Start a new discussion instead.