redefinition of ‘class error...

I've encountered this error when I wrote a new class:
============================================================
error: invalid use of incomplete type ‘class MobileNode’
class MyNode : public MobileNode

error: redefinition of ‘class MyNode’
class MyNode : public MobileNode

error: previous definition of ‘class MyNode’
class MyNode : public MobileNode
============================================================
the class is:

#pragma once
class MyNode;
#ifndef __ns_mynode_h__
#define __ns_mynode_h__
#include "object.h"
#include "trace.h"
#include "lib/bsd-list.h"
#include "phy.h"
#include "topography.h"
#include "arp.h"
#include "node.h"
#include "gridkeeper.h"
#include "energy-model.h"
#include "location.h"
#include "mac-tdma.h"
#include <iostream>
#endif

class MyNode;
class MyNode : public MobileNode
{
friend class MacTdma;
friend class MobileNode;
public:

MyNode();
};
#endif // ns_mynode_h


why do you have 2 forward declares? I have never done that, but it looks suspect... take the second one out...

class MyNode;
... bunch of stuff
class MyNode;

and I am also not sure if it matters if the first one is in the once or not. It probably does not matter.
Last edited on
I don't think the forward declaration really matter (could be wrong), but the big red flag i see is that you have 1 #if____ macro, but 2 #endif macros.
Topic archived. No new replies allowed.