I'm using Visual Studio 2008 express and I'm simply trying to put my source in different files. I have my Definitions in my .h file, my definitions in my cpp file, and my main.cpp file. I thought this was the correct way of doing things but the linker still has problems resolving my implemented functions. Here's my code:
The main code:

#include<iostream>
#include "NumberGenerator.h"
using namespace std;


int main(int argc, char* argv[])
{
	NumberGenerator h;
	//for(int x=0; x < 10; x++)
	//	cout<<fn.generateNums(10);
	return 0;
}

The definitions(NumberGenerator.h)

#ifndef FN_Gen
#define FN_Gen
class NumberGenerator
{
public:
	NumberGenerator();
	static double generateNums(int max);
};

#endif

The implementation:

#include "NumberGenerator.h"
//main class for Function module
double NumberGenerator::generateNums(int max)
{
	double x=.5;
	x=x*x;
	if(x > max) x=2;

	return x;
}

I get unresolved external error: error LNK2019: unresolved external symbol "public: __thiscall NumberGenerator::NumberGenerator(void)" (??0NumberGenerator@@QAE@XZ) referenced in function _main
I don't understand becuase I included the .cpp in the project. What am I missing? I searched through this all over I can't find a solution. A link or a simple explanation will do. Thanks.

you never implemented the class constructor.

you never implemented the class constructor.

I missunderstood, I thought C++ used the default(empty) constructor if its not implemented. But anyway it works now, thanks!

I missunderstood, I thought C++ used the default(empty) constructor if its not implemented.

Only if you do not declare a constructor in the class.

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.