main.cpp using sphere library

Hey, guys.

I am having problems with compiling the files, and I can't figure out the problem.

Here is the code:

main.cpp

1
2
3
4
5
6
7
8
9
#include "sphere.h"
#include <iostream>
using namespace std;

int main()
{
	Sphere* sphere = new Sphere;
	sphere -> invertcolors();
}


sphere.h

1
2
3
4
5
class Sphere
{
	public:
	void invertcolors();
};


sphere.cpp

1
2
3
4
5
6
7
8
9
#include "sphere.h"
#include <iostream>
using namespace std;


void Sphere::invertcolors()
{
	cout << "inverted" << endl;
}


I am getting the undefined reference error, and I do not know why.

Any ideas?

Thanks!
Last edited on
which compiler are you using?
if(MSVC)
ensure all these 3 files listed in the project tree
else if(g++)
g++ -o test.exe main.cpp sphere.cpp
Topic archived. No new replies allowed.