Archived

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

Templated member functions in GCC

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

I'm trying to write a templated string class that can be converted to another string class of a different character type. However, I'm having some trouble with the templated member functions. I think my syntax is correct, but Dev-C++/GCC 3.2 keeps giving me strange errors. Here's the relevant code:
template< typename CharType >
	class String
{
public:
	/** Constructs the string from a string of a different character
	 *  type.
	 */
	template< typename OtherCharType >
		String(const String< OtherCharType > &other);

private:
	std::vector< CharType >
};
   
template< typename CharType >
	template< typename OtherCharType >
		String< CharType >::String< OtherCharType >(const String< OtherCharType > &other)
{
	data_.assign(other.data_.begin(), other.data_.end());
}
   
Here's the related error messages:
Code/lang/String.hpp:211: `String< OtherCharType >' specified as declarator-id
Code/lang/String.hpp:211: no `int 
   lang::String< CharType >::String< OtherCharType >(const 
   lang::String< OtherCharType >&)' member function declared in class `
   lang::String< CharType >'
Code/lang/String.hpp:211: template definition of non-template `int 
   lang::String< CharType >::String< OtherCharType >(const 
   lang::String< OtherCharType >&)'
  
[edited by - dcosborn on November 27, 2003 5:42:17 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by dcosborn

template< typename CharType >
template< typename OtherCharType >
String< CharType >::String< OtherCharType >(const String< OtherCharType > &other)




Hi

I think that should be


template< typename CharType >
template< typename OtherCharType >
String<CharType>::String(const String<OtherCharType> &other)



[edited by - jingo on November 27, 2003 5:57:38 AM]

Share this post


Link to post
Share on other sites