reference problem with class

hey guys.. this is only my second time doing oop so please help

im getting this problem:
1>2_8.obj : error LNK2019: unresolved external symbol "public: void __thiscall sharhan_1::quad::evaluate(float)" (?evaluate@quad@sharhan_1@@QAEXM@Z) referenced in function _main
1>2_8.obj : error LNK2019: unresolved external symbol "public: void __thiscall sharhan_1::quad::retreive(void)" (?retreive@quad@sharhan_1@@QAEXXZ) referenced in function _main
1>2_8.obj : error LNK2019: unresolved external symbol "public: void __thiscall sharhan_1::quad::change(float,float,float)" (?change@quad@sharhan_1@@QAEXMMM@Z) referenced in function _main
1>2_8.obj : error LNK2019: unresolved external symbol "public: __thiscall sharhan_1::quad::quad(float,float,float,float)" (??0quad@sharhan_1@@QAE@MMMM@Z) referenced in function _main


and here's the code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*********************************************************
* file name: 2_8.cpp
* date created:  1/18/12
* date of last revision: 1/20/12
* details of the revision: none
* short description: quadratic evaluation
**********************************************************/

#include "quad.h"
#include <iostream>
#include <string>
#include <cstdlib>
#include <iomanip>
using namespace std;
using namespace sharhan_1;
//function prototypes
void desc();


int main()
{
	// Program description
	desc();

	//initiliazation
	char num='h';
	float x=0, a=0, b=0, c=0;

		//class declaration
	quad quad(x,a,b,c);

	while (num!='0')
	{
		cout <<"What would you like to do?"<<endl
			 <<"1. Change the values of the quadratic formula"<<endl
			 <<"2. retreive the current values"<<endl
			 <<"3. evaluate the values at a certain value of x"<<endl
			 <<"0. To exit"<<endl;
		cin >> num;

		switch (num)
		{
		case '1':
			cout << "Please enter the A, B and C values respectively \nasn in ax^2+bx+c"<<endl<<endl;
			cin >> a >> b >> c;
			quad.change(a, b, c);
			break;
		case '2':
			quad.retreive();
			break;
		case '3':
			cout << "Please enter the value of x"<<endl;
			cin >> x;
			quad.evaluate(x);
			break;
		case '0':
			break;
		default:
			cout << "ERORR: Please enter a valid number"<<endl;
			break;
		}
	}
	return 0;
}

//function implementations
void desc()
{
		cout << "This program will accept and evaluate" <<endl
			 << "the quadratic formula at a certain value of x\n\n";
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include<iostream>
#include <cmath>
#include <cstdlib>
#include "dim.h"
#include <iomanip>

using namespace std;
using namespace sharhan_1;

namespace sharhan_1
{
	dim::dim(float x, float y, float z, float t)
	{
		xx = x;
		yy = y;
		zz = z;
		tt = t;
	}
	void dim::set(float x, float y, float z)
	{
		xx = x;
		yy = y;
		zz = z;
	}
	void dim::shift(float x, float y, float z)
	{
		xx += x;
		yy += y;
		zz += z;
	}
	void dim::coor()
	{
		cout <<setiosflags(ios::fixed)<<setprecision(2);
		cout << "x: " <<xx <<"\ny: " <<yy <<"\nz: " <<zz<<endl<<endl;
	}
	void dim::sett(float t)
	{
		t = tt;
	}
	void dim::rotx(float tt)
	{
		//x-axis
		xx = xx;
		yy = yy*cos(tt) - zz*sin(tt);
		zz = yy*sin(tt) + zz*cos(tt);
		cout <<setiosflags(ios::fixed)<<setprecision(2);
		cout << "x: " <<xx <<"\ny: " <<yy <<"\nz: " <<zz<<endl<<endl;
	}
	void dim::roty(float tt)
	{
		//y-axis
		xx = xx*cos(tt) + zz*sin(tt);
		yy = yy;
		zz = -xx*sin(tt) + zz*cos(tt);
		cout <<setiosflags(ios::fixed)<<setprecision(2);
		cout << "x: " <<xx <<"\ny: " <<yy <<"\nz: " <<zz<<endl<<endl;
	}
	void dim::rotz(float tt)
	{
		//z-axis
		xx = xx*cos(tt) - yy*sin(tt);
		yy = xx*sin(tt) + yy*cos(tt);
		zz = zz;
		cout <<setiosflags(ios::fixed)<<setprecision(2);
		cout << "x: " <<xx <<"\ny: " <<yy <<"\nz: " <<zz<<endl<<endl;
	}
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#ifndef QUAD_H
#define QUAD_H

namespace sharhan_1
{
	class quad
	{
		private:
			float xx;
			float aa;
			float bb;
			float cc;
		public:
			quad(float xx, float aa, float bb, float cc);
			void change(float a, float b, float c);
			void retreive();
			void evaluate(float x);
	};
}
#endif 


this is driving me crazy.. idk what the problem is.. thanks in advance
99 times out of 100, "unresolved external symbol" means that the linker cannot find a body for a function.

If you'll notice, the linker is spitting out errors for these functions:

quad::evaluate
quad::retreive
quad::change
quad::quad

You'll also notice that nowhere in your code did you give those functions a body.
<code>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include "quad.h"
#include <iomanip>

using namespace std;
using namespace sharhan_1;

namespace sharhan_1
{
quad::quad(float x, float a, float b, float c)
{
xx = x;
aa = a;
bb = b;
cc = c;
}
void quad::change(float a, float b, float c)
{
aa = a;
bb = b;
cc = c;
}
void quad::retreive()
{
cout << aa<<"x^2+"<<bb<<"x+"<<cc<<endl;
}
void quad::evaluate(float x)
{
xx = x;
cout << aa * pow(xx,2) + bb * xx + cc <<endl;
}
}
</code>

im sorry, i posted the wrong implementation from another project.. this is the right one and i did give them a body but still the same problem
bump.. i still need help guys
Have you included then all files necessary in your project? You must have forgotten something there.

Also when publishing code please inform in which file belong every code. I guess the first is your main.cpp, the second is some source file and the third your quad.h file?

Then you extra post is your quad implementation (source code like quad.cpp?)?

Anyway there is a linking error that means you have probably skipped some file in your project
first is 2_8.cpp which is the program
the second is a wrong implementation file form another program
third is quad.h
fourth is the quad implementation

I still don't know what the problem is because it seems like I included everything
A simple test is to put obviously wrong code in your quad.cpp file. Something like this:

1
2
3
4
5
6
7
8
9
10
//...
quad::quad(float x, float a, float b, float c)
{
  xx = x;
  aa = a;
  bb = b;
  cc = c;

  foobarbaz;  // <- this will make a compiler error
}


Do that and rebuild.

If you don't get a compiler error, you know it's not compiling (and therefore not linking) that cpp file.

Like eypros said, make sure this particular cpp file is added as part of your project. Simply having it open in the IDE is not enough. It must be among the projects files.
oh wow.. that really helped. I realized that I set my implementation file as a .h and then manually changed it. stupid visual studio probably didnt realize that. I just made a new .cpp file and copied everything to it so now it works.. thanks again
Topic archived. No new replies allowed.