1

I don't understand why the following code cannot be compiled:

// program.h
class Sensor;

class Program {
private:
    static Sensor* sensor;
public:
    void SetSensor(Sensor *s) { sensor = s; }
};

I get this compiler error: cc3No0Or.ltrans0.ltrans.o*: In function Program::SetSensor(Sensor*) program.h:##: undefined reference to Program sensor

Franziee
  • 621
  • 11
  • 28

1 Answers1

2

You only have a declaration for the static member, you need also the definition... Add

Sensor* Sensor::sensor;

in a .cpp file and it will work.

6502
  • 112,025
  • 15
  • 165
  • 265