R
Ruben Campos
I've found a problem with types defined inside a template. With a
non-template class, I can write the following:
// MyClass.hpp
class MyClass
{
// ...
typedef unsigned int MyType;
MyType MyMethod ( /* ... */ );
// ...
};
// MyClass.cpp
MyClass::MyType
MyClass::MyMethod ( /* ... */ )
{
// ...
}
This code works well. Of course, I can include a using declaration "using
MyClass::MyType" in MyClass.cpp file, before MyMethod implementation,
instead of specifying the path in its return value.
Well, my problem is that this don't work with templates:
// MyTemplate.hpp
template <typename T>
class MyTemplate
{
// ...
typedef unsigned int MyType;
MyType MyMethod ( /* ... */ );
// ...
};
// MyTemplate.cpp
template <typename T>
MyTemplate <T>::MyType
MyTemplate <T>::MyMethod ( /* ... */ )
{
// ...
}
Is there any alternative way to do this? I've thought to place type
definition outside the class, but this is not correct due to visibility
restrictions (it would make the type visible outside the class, which is not
always desired). Could I include a forward declaration inside the class
declaration (MyTemplate.hpp), and define it at the beginning of
MyTemplate.cpp?
Thank you very much in advance for your help
non-template class, I can write the following:
// MyClass.hpp
class MyClass
{
// ...
typedef unsigned int MyType;
MyType MyMethod ( /* ... */ );
// ...
};
// MyClass.cpp
MyClass::MyType
MyClass::MyMethod ( /* ... */ )
{
// ...
}
This code works well. Of course, I can include a using declaration "using
MyClass::MyType" in MyClass.cpp file, before MyMethod implementation,
instead of specifying the path in its return value.
Well, my problem is that this don't work with templates:
// MyTemplate.hpp
template <typename T>
class MyTemplate
{
// ...
typedef unsigned int MyType;
MyType MyMethod ( /* ... */ );
// ...
};
// MyTemplate.cpp
template <typename T>
MyTemplate <T>::MyType
MyTemplate <T>::MyMethod ( /* ... */ )
{
// ...
}
Is there any alternative way to do this? I've thought to place type
definition outside the class, but this is not correct due to visibility
restrictions (it would make the type visible outside the class, which is not
always desired). Could I include a forward declaration inside the class
declaration (MyTemplate.hpp), and define it at the beginning of
MyTemplate.cpp?
Thank you very much in advance for your help