K
kalki70
Hi,
I'm working with templates, but I have a syntax problem I don't know
how to fix.
I built a small example, so maybe you can tell me how to write
correctly this code.
I have 2 files : template.H and template.C
Template.H :
#ifndef _TEMPLATE_H_739832983298
#define _TEMPLATE_H_739832983298
template <class T>
class MyTemplate
{
class OtherClass
{
int foo;
};
T value;
public:
OtherClass changeValue(OtherClass newValue);
};
#endif
Template.C :
#include <template.H>
return newValue;
}
Here is my problem, I don't know how to make the definition of method
changeValue().
If it returns and receives a simple parameter, like int, I have no
problem, but the return type and parameter type is another class
defined inside MyTemplate.
Working in Solaris, compiling with CC I get the following warning.
"/home/usuarios/lrojas/engine2.5/src/template.C", line 4: Warning
(Anachronism): Type names qualified by template parameters require
"typename".
"/home/usuarios/lrojas/engine2.5/src/template.C", line 4: Warning
(Anachronism): Type names qualified by template parameters require
"typename".
In Linux/g++ it doesn't even compile, it generates an error instead of
a warning.
template.C:4: error: expected constructor, destructor, or type
conversion before "MyTemplate"
What is the right syntax to define methods for MyTemplate, when I need
to use a parameter type defined inside MyTemplate, like "OtherClass" ?
I've been reading some tutorials on templates in internet, but couldn't
find this situation.
Thanks for any advice!
Luis
I'm working with templates, but I have a syntax problem I don't know
how to fix.
I built a small example, so maybe you can tell me how to write
correctly this code.
I have 2 files : template.H and template.C
Template.H :
#ifndef _TEMPLATE_H_739832983298
#define _TEMPLATE_H_739832983298
template <class T>
class MyTemplate
{
class OtherClass
{
int foo;
};
T value;
public:
OtherClass changeValue(OtherClass newValue);
};
#endif
Template.C :
#include <template.H>
{template said:::OtherClass newValue)
return newValue;
}
Here is my problem, I don't know how to make the definition of method
changeValue().
If it returns and receives a simple parameter, like int, I have no
problem, but the return type and parameter type is another class
defined inside MyTemplate.
Working in Solaris, compiling with CC I get the following warning.
"/home/usuarios/lrojas/engine2.5/src/template.C", line 4: Warning
(Anachronism): Type names qualified by template parameters require
"typename".
"/home/usuarios/lrojas/engine2.5/src/template.C", line 4: Warning
(Anachronism): Type names qualified by template parameters require
"typename".
In Linux/g++ it doesn't even compile, it generates an error instead of
a warning.
template.C:4: error: expected constructor, destructor, or type
conversion before "MyTemplate"
What is the right syntax to define methods for MyTemplate, when I need
to use a parameter type defined inside MyTemplate, like "OtherClass" ?
I've been reading some tutorials on templates in internet, but couldn't
find this situation.
Thanks for any advice!
Luis