Beeper program

Jan 29, 2011 at 3:18pm

Hello again, I have been asked to develop a BEEPER code program into the following code. Everything is fine but I keep getting this error code:-

1>main.obj : error LNK2001: unresolved external symbol "private: static class Beeper * Beeper::beepero" (?beepero@Beeper@@0PAV1@A)

this is the main file:-

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
#include <Windows.h>
#include "header.h"

using namespace std;

int main(void) 
{
	Beeper * beeper;
	//beeper = new Beeper(500,1000);
	Beeper::create(500,1000);
	beeper -> beep();
	return 0;
}




this is the header file:-


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
#include <iostream>
#include <Windows.h>

using namespace std;

class Beeper
{
private:
	int FREQ;
	int DUR;
	static Beeper * beepero;
public:
	Beeper(unsigned int freq, unsigned int dur) { FREQ = freq; DUR = dur; }
	static Beeper * create(unsigned int frequency, unsigned int duration);
	void beep();
};

inline void Beeper::beep()
{
	cout << Beep(FREQ, DUR);
}

Beeper* Beeper::create(unsigned int frequency, unsigned int duration)
{
	if(Beeper::beepero == NULL)
	{
		Beeper::beepero = new Beeper(frequency, duration);
	} 
	else 
	{
		Beeper::beepero = Beeper::beepero;
	}
	return Beeper::beepero;
}



thanks for the help in advance!
Jan 29, 2011 at 4:10pm
you must write Beeper *Beeper::beepero = NULL; in your cpp file.

alternatively you can move static Beeper * beepero; into your 'create' function and use it directly.


Btw. your 'create' funciton is not inline and is not supposed to be in the header. if you'd include that more than once you get a linker error.
Jan 29, 2011 at 4:18pm
What does line 31 do?
Topic archived. No new replies allowed.