I am writing a project which contains two template classes
ListManipulator will create lists with etiher int or double
UserInterface will have the output functions and has ListManipulator as a member.
When i try to initialize them, i get the error:
1 2 3
State
Error C2440 'initializing': cannot convert from 'std::list<float,std::allocator<_Ty>> **' to 'std::list<float,std::allocator<_Ty>> *' listmanipulator.h 18
Error C2439 'ListManipulator<float>::theList': member could not be initialized listmanipulator.h 18
Severity Code Description Project File Line Suppression State
Error C2512 'ListManipulator<T>': no appropriate default constructor available userinterface.h 29
If it gave you an error, you probably incorporated it into your code incorrectly.
It is strange that you pass a pointer to the list ... why?
And then you initialize theList with the ADDRESS OF THE POINTER? Is that really what you want?
You shouldn't need to use pointers at all here.
I did doublecheck it and i used it the same way you did, i even removed the pointer.
Now i can not run any UserInterface function from main, giving me LNK2019 error, and i have checked with different function but non work, they are all defined correctly...
Can't really understand what it could be. When I dont call for any functions, the program runs fine, but as soon as i initiate finalUI and call for a function, it doesnt compile.
You aren't handling the template classes properly. The easiest thing for you to do is to put the implementations in the headers. A common way of doing this is to rename your cpp files to tpp (template implementation file) and include it at the end of the associated header file. Remove the includes of the header in the tpp files, of course. When I do that, it works fine.
Yes. And UserInterface.cpp needs to be in UserInterface.h. But like I said, you can simply include the source code files at the end of the .h files. It's usual to use a tpp suffix for such files. Remove the includes of the headers from the tpp files, though.