My compiler issued the following error :
matrix.o: In function `Matrix::modify_cell(unsigned int, unsigned int, int)':
Matrix.cpp:(.text+0x5f): undefined reference to `operator!(Dim)'
Matrix.cpp:(.text+0xa3): undefined reference to `operator!(Dim)'
Matrix.cpp:(.text+0x178): undefined reference to `operator!(Dim)'
Matrix.cpp:(.text+0x1a0): undefined reference to `operator!(Dim)'
matrix.o: In function `List::nula(Dim) const':
Matrix.cpp:(.text._ZNK4List4nulaE3Dim[List::nula(Dim) const]+0x11): undefined reference to `operator!(Dim)'
list1.o:List - auxiliary methods.cpp:(.text+0x3b): more undefined references to `operator!(Dim)' follow
collect2: ld returned 1 exit status
make: *** [app] Error 1
Matrix is a class placed in file Matrix.h and Matrix.cpp that inherits from the class List, that in turn is placed in List.h and two other .cpp files. Type Dim (typedef) and operator! for it are declared globally (outside of any class) in aux.h included to List.h and the operator! is defined in aux.cpp. In Matrix.h I include List.h so I do not understand what is the problem. aux.cpp is indeed compiled in my makefile to .o and then joined into single app.
I know that it would be better to place my typedef Dim and its overloaded operator into a class, but it is used both in class List and class Matrix while typedefs are not inherited and I have no idea for any other workaround.
EDIT:
// aux.cpp
#include "aux.h"
Dim operator!(Dim dim) { return dim == COL ? ROW : COL; }
// aux.h
#ifndef AUX_H
#define AUX_H
/* (...) */
typedef enum { ROW, COL } Dim;
inline Dim operator!(Dim dim);
#endif
You’ve declared
operator!(Dim)as inline, so it isn’t available unless you also include the definition in the .h. Either move the definition or take out theinline.