Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Promit

(C++) Working with a non-typed template?

This topic is 5368 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Suppose i have a template like so:
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]

Share this post


Link to post
Share on other sites
Advertisement
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 ]

Share this post


Link to post
Share on other sites
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;
};


Share this post


Link to post
Share on other sites
Guest Anonymous Poster
(Off topic)


//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...

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
thankyou guys

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!