template
struct SomeType
{
int SomeID;
T* Data;
}
And I want to write a routine that works with that struct and SomeID, but doesn't care about Data. Could I write a function that takes a SomeType instead of a SomeType<> and works with it like that?
(This is just for curiosity's sake, btw, no real application at the moment)
Actually, now that I think of it, could I write a templatized function and just use the template class as the SomeType class type to achieve the same thing?
[edited by - Promit on October 9, 2003 9:12:54 PM]
(C++) Working with a non-typed template?
Suppose i have a template like so:
Could I write a function that takes a SomeType instead of a SomeType<> and works with it like that?
No. Declaring a SomeType template doesn''t mean ''plain'' SomeType exists.
Actually, now that I think of it, could I write a templatized function and just use the template class as the SomeType class type to achieve the same thing?
Yes. Either
template <class T> int Func( T arg );
or
template <class T> int Func( SomeType<T> arg );
[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]
No. Declaring a SomeType template doesn''t mean ''plain'' SomeType exists.
Actually, now that I think of it, could I write a templatized function and just use the template class as the SomeType class type to achieve the same thing?
Yes. Either
template <class T> int Func( T arg );
or
template <class T> int Func( SomeType<T> arg );
[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]
You could also put SomeID into a non-templated base class, e.g.:
struct SomeTypeBase { int SomeID; };template <class T> struct SomeType : public SomeTypeBase{ T* Data;};
(Off topic)
I don''t think anybody knows...
//Just wondering, but why isn''t this typdef legal????:typedef delete delete_the_thing_pointed_to_by;int* ip = new int;delete_the_thing_pointed_to_by ip;
I don''t think anybody knows...
i thought typedef only applied to data types(ie. int, float, double, char, struct, class) . not keywords (ex. delete, new, if, else, etc).
delete
is an operator, not a type. [ Google || Start Here || ACCU || STL || Boost || MSDN || GotW || CUJ || MSVC++ Library Fixes || BarrysWorld || E-Mail Me ]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement