Add constant object to linked list of objects

I have a standard linked list in template format (with T being the typename) with the following relevant insertion operators:

1
2
bool      PushFront  (const T& t);   // Insert t at front of list
bool      PushBack   (const T& t);   // Insert t at back of list 


I want to build a list of pointers to objects (we'll call them objects of class Box for simplicity) that is member data for a parent class (we'll call that class Warehouse). However, I want to have a constant Box

const Box INVISIBLE_BOX = Box();

that represents a nonexistent Box. However, I cannot use either

1
2
3
PushFront(&INVISIBLE_BOX)
or
PushBack(&INVISIBLE_BOX)


to add INVISIBLE_BOX to the list of boxes without getting an invalid conversion error

invalid conversion from âconst warehouse::Box*â to âwarehouse::Box*â [-fpermissive]

What can I do to make it take a constant Box?
I am using g++ to compile these files.
Last edited on
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
35
36
37
38
39
#include <iostream>
using namespace std;

class Box{};

template <typename T>
class Warehouse
{
    T value;
    Warehouse<T> *next;
public:
    bool PushFront(const T& t);
    bool PushBack(const T& t);

};

template <typename T>
bool Warehouse<T>::PushFront(const T& t)
{
	return true;
}

template <typename T>
bool Warehouse<T>::PushBack(const T& t)
{
	return true;
}

int main() 
{
	Warehouse<Box> wareHouseObject;
	wareHouseObject.PushFront(Box());
	wareHouseObject.PushBack(Box());
	
	const Box obj1, obj2;
	wareHouseObject.PushFront(obj1);
	wareHouseObject.PushBack(obj2);
	return 0;
}
Topic archived. No new replies allowed.