Good afternoon Daniweb, I have a simple (and probably idiotic) problem today, I have a simplistic program that simulates a Train station, trains come in, they go into a stationDock and come out after a while.
The stationDocks are an array of trains, either pointing to a train or being NULL (at least that's what it should be, I probly did an error somewhere in the implementation)

WideVar.cpp: In static member function ‘static void wideVar::freeDock(int)’:
WideVar.cpp:67: error: no match for ‘operator=’ in ‘*(((Train*)(((unsigned int)i) * 36u)) + wideVar::stationDocks) = 0’
Train.h:7: note: candidates are: Train& Train::operator=(const Train&)
WideVar.cpp: In static member function ‘static bool wideVar::dockIsEmpty(int)’:
WideVar.cpp:69: error: no match for ‘operator==’ in ‘*(((Train*)(((unsigned int)i) * 36u)) + wideVar::stationDocks) == 0’
WideVar.cpp: In static member function ‘static void wideVar::setDock(int, Train*)’:
WideVar.cpp:71: error: no match for ‘operator=’ in ‘*(((Train*)(((unsigned int)i) * 36u)) + wideVar::stationDocks) = train’
Train.h:7: note: candidates are: Train& Train::operator=(const Train&)
WideVar.cpp: In static member function ‘static int wideVar::compareDock(int, Train*)’:
WideVar.cpp:73: error: base operand of ‘->’ has non-pointer type ‘Train’
WideVar.cpp:73: error: expected `}' at end of input

P.S. I commented out (only in the example) the parts of the code unrelated to the problem.

#include <stdlib.h>
#include "WideVar.h"

extern int STATION_ROOM;
extern int TRAIN_START_ID;

/*
	static LinkedList eventList = LinkedList(); 
	static LinkedList trainList = LinkedList(); 
	static Queue inQueue = Queue(); 
	static Queue outQueue = Queue(); 
*/
	static int dockLength = STATION_ROOM;
	static int freeDocks = dockLength;
	static Train* stationDocks = new Train[dockLength]; 
	static int trainIdStart = TRAIN_START_ID;
/*
	void wideVar::insertEvent(Event* newIS)
		{eventList.insert(newIS);}
	bool wideVar::checkEmptyEvent()
		{return eventList.isEmpty();}
	Event* wideVar::returnTopEvent()
		{return dynamic_cast<Event*>(eventList.Top->item);}
	void wideVar::removeTopEvent()
		{eventList.removeTop();}
	void wideVar::printTrains()
		{trainList.print();	}

	void wideVar::destroyTrains()
		{trainList.~LinkedList();}
	void wideVar::destroyEvents()
		{eventList.~LinkedList();}

	void wideVar::inPush(Train* train)
		{inQueue.push(train);}
	Train* wideVar::inPop()
		{return (Train*) inQueue.pop();}
	Train* wideVar::inPeek()
		{return (Train*) inQueue.peek();}
	int wideVar::getInLength()
		{return inQueue.getLength()}

	void wideVar::outPush(Train* train)
		{outQueue.push(train);}
	Train* wideVar::outPop()
		{return (Train*) outQueue.pop();}
	Train* wideVar::outPeek()
		{return (Train*) outQueue.peek();}
	int wideVar::getOutLength()
		{return inQueue.getLength();}
	
	void wideVar::destroyIn()
		{inQueue.~Queue();}
	void wideVar::destroyOut()
		{outQueue.~Queue();}

	int wideVar::trainId()
		{return trainIdStart++;}

	void wideVar::freeDocksNumDown()
		{freeDocks--;}
	void wideVar::freeDocksNumUp()
		{freeDocks++;}
	int wideVar::freeDocksReturn()
		{return freeDocks;}
*/
	void wideVar::freeDock(int i)
		{stationDocks[i] = NULL;}
	bool wideVar::dockIsEmpty(int i)
		{return stationDocks[i] == NULLz;}
	void wideVar::setDock(int i, Train* train)
		{stationDocks[i] = train;}
	int wideVar::compareDock(int i, Train* train)
		{return stationDocks[i]->compareTo(train);

Thank you very much for your help!

You're trying to assign NULL to a Train object, or to compare NULL to a Train object. You haven't overloaded the = and == operators, and it wouldn't make sense to assign or compare NULL in any case.

ar is the pointer - that can be assigned or compared to NULL. But assigning NULL will orphan your entire array of Train objects.

If your goal is to show that an element of the ar array is available, you might add a marker to the Train objects (valid or invalid).

If you want to be able to actually delete a Train object, consider making ar a pointer to pointers.

static Train** stationDocks = new Train *[dockLength]; 
for( int i = 0; i < dockLength; i++ )
   ar[i] = new Train;

I see, yea, in hindsight an array of pointers was probly what I was aiming for but was butchering in implementation. Thank you very much!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.