I am new to templates, and I have been forced to use one in a function while the underlying class used is not a template. A very simple case where my problem occurs is the following :
//test.h
struct Top
{
struct Bottom
{
};
Bottom bot;
};
//test.cpp
void without_template(Top content)
{
Top::Bottom bot = content.bot;
}
template<typename T>
void with_template(T content)
{
// Uncomment to get an error :
// T::Bottom bot = content.bot;
}
template<typename T>
void with_template_2(T content)
{
auto bot = content.bot;
}
(Currently, my code works using "auto", but I would like to avoid using it like that, this looks really unsafe.) (Also, in the actual code, everything is in .h, but the same thing occurs.)
The error is C2760 : syntax error: expected ";" after "T" ; followed by C7510 : 'Bottom' : a dependent type name has to be preceeded by 'type name' (sorry for not quoting it exactly, my compiler is in French)
I though templates were basically just inlining the type name, but apparently not. So what is going on here ? In particular, there is an error even if "with_template" is never called...
My best guess is that the syntax "T::..." is simply not supported, but I don't see why that would be the case.
Is there an elegant fix ? (appart from making the underlying class a template, which would just propagate the use of templates in my code)
(I also tried "using namespace", but it doesn't seem to work.)