Hello, I am just implementing a smart pointer class as a little exercise and have these two files "test.h" (library) and "test_main.c" (main program). When I try to compile these two files using:
g++ test_main.c -o test_main
I get the following error(s):
test_main.c: In function ‘int main(int, char**)’:
test_main.c:14:22: error: type/value mismatch at argument 1 in template parameter list for ‘template<class type> class smart_pointers::smart_pointer’
test_main.c:14:22: error: expected a type, got ‘link’
test_main.c:14:26: error: invalid type in declaration before ‘=’ token
test_main.c:14:32: error: expected type-specifier before ‘link’
test_main.c:14:32: error: invalid conversion from ‘int*’ to ‘int’
test_main.c:14:32: error: expected ‘,’ or ‘;’ before ‘link’
test_main.c:15:5: error: base operand of ‘->’ is not a pointer
test_main.c:16:20: error: base operand of ‘->’ is not a pointer
Why is this happening? When I rename all instances of "link" in test_main.c it compiles and runs fine... But I need the program to work without changing the test_main.c file (the class should be called "link" and nothing else).
#include "test.h"
usingnamespace smart_pointers;
class link
{
public:
smart_pointer<link>next;
int data;
};
int main(int argc, char*argv[])
{
smart_pointer<link> l = new link();
l->data = 5;
printf("%d\n", l->data);
}