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();
}

Recommended Answers

All 4 Replies

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

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 :).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.