I am writing a set of related list functions for a project.
I need to provide flexibility regarding data type in list nodes (int / char)
So, I'm trying to do something like this:
in main.cpp
#define INT_DATA
#include "lists.h"
....
on the lists.h
#ifdef CHAR_DATA
typedef char DATA_TYPE;
#endif
#ifdef INT_DATA
typedef int DATA_TYPE;
#endif
typedef struct lnode {
DATA_TYPE data;
struct lnode* next;
} LNODE;
LNODE * createNewListNode(DATA_TYPE data, LNODE* next);
....
but all this does not seem to work ... I do not want to write duplicate code when only prototypes are different.
What am I doing wrong? Is it possible?
NOTE
This exercise, I can’t use classes, I can’t use any standard libraries
source
share