Jump to content
  • Advertisement
Sign in to follow this  
Rattrap

Default Template Arguements

This topic is 4807 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

typedef unsigned int s32;

template <typename Indexer = s32>
class PAscii
{
public:
	~PAscii(void);
	static Indexer strlen(const void* const pString);
	PAscii& operator= (const PAscii& rhs);
	char& operator[] (const Indexer& intIndex);
	const char& operator[] (const Indexer& intIndex) const;
	Indexer getLength(void) const;
	PAscii toUpper(void) const;
	PAscii toLower(void) const;
	Indexer getIndexOf(const char chr, Indexer intStartingIndex = 0) const;
	Indexer getIndexOf(const KS::String::CString<PAscii>& str, Indexer intStartingIndex = 0) const;
	static const Indexer INDEX_NOT_FOUND = -1;
protected:
	PAscii(const void* const pString);
	PAscii(const void* const pString, const Indexer& intLength, const bool& blnCopy = true);
	PAscii(const Indexer& intLength, const bool& blnZero = false);
	PAscii(const PAscii& rhs);
	char*	m_pString;
	Indexer	m_intLength;
};

template <typename PCharset>
class CString : public PCharset
{
public:
	CString(const void* const pString);
	CString(const void* const pString, const s32& intLength);
	CString(const s32& intLength, const bool& blnZero = false);
	CString(const PCharset& rhs);
	~CString(void);
};

CString<PAscii> str1 = CString<PAscii>("This is the song that never ends.");

Now what I understand of template default values, I shouldn't have to actually do something like CString<PAscii<s32> > if I wanted to do something other than the default value. The default value doesn't seem to be taking in this case. I get compiler errors with this code, until I explicitly use CString<PAscii<s32> >. Shouldn't I just be able to use CString<PAscii> since a default value is assigned for Indexer in the PAscii class?

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Rattrap
*** Source Snippet Removed ***

Now what I understand of template default values, I shouldn't have to actually do something like CString<PAscii<s32> > if I wanted to do something other than the default value. The default value doesn't seem to be taking in this case. I get compiler errors with this code, until I explicitly use CString<PAscii<s32> >. Shouldn't I just be able to use CString<PAscii> since a default value is assigned for Indexer in the PAscii class?


CString< PAscii<> >

Share this post


Link to post
Share on other sites
Like he said. It's still a template even if there are no non-defaulted arguments to specify.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!