static structure deceleration not working in C++

Hi guys,

I have a structure called PDU in llcp.h, also in here is a class called LLCP, inside which I'm creating a static instance of the PDU structure, however, when I attempt to define this static member variable in my cpp file, I receive the message: "error: 'PDU' has not been declared", here's the code:

llcp.h

struct PDU
{
	byte dsap;
	byte ptype;
	byte ssap;
	byte sequence;
	byte payload[256];
};

class LLCP
{
public:

	static PDU pdu;

	static void receive();
};

llcp.cpp

#include "llcp.h"

PDU LLCP::pdu = 0;

Any ideas guys?

Many thanks

This doesn't make sense. First you already declared LLCP::pdu to be of type PDU, so no need to do it again in the .cpp file. Then you cannot set a structure to value 0. What would you expect that to do? Fill the structure with zeros?

pylon:
This doesn't make sense. First you already declared LLCP::pdu to be of type PDU, so no need to do it again in the .cpp file. Then you cannot set a structure to value 0. What would you expect that to do? Fill the structure with zeros?

It does, I've declared pdu in the header but not defined it, which in C/C++ because it's static needs doing in the namespace in the C++ source file. I don't need the = 0, but the problem still occurs even if I omit this.

Your syntax is slightly off. There are a couple of ways to initialise struct members to default values. The old way is { 0 } the new way is PDU(). I flipped a coin and will show the old way. The following compiles:

struct PDU
{
	byte dsap;
	byte ptype;
	byte ssap;
	byte sequence;
	byte payload[256];
};

class LLCP
{
public:

	static PDU pdu;

	static void receive();
};

PDU LLCP::pdu = { 0 }

void setup() {
}

void loop() {
}

NVM problem solved, was to do with a dodgy define elsewhere.