I'm trying to port some Visual C++ (VS2005) code so that it will compile under both VS2005 and C++ Builder XE. The code that follows compiles fine under VS2005 but under C++ Builder XE, I get the following error:
[BCC32 Error] time_stamp.h(49): E2327 Operators may not have default argument values
Here is the code in question: (time_stamp.h)
template<typename counter_type>
class time_stamp
{
typedef time_span<counter_type> time_span_type;
typedef typename counter_type::value_type value_type;
public:
/* some code removed for sake of this post, next line is the one causing the error */
friend time_span<counter_type> operator-(const time_stamp<counter_type> &first, const time_stamp<counter_type> &second)
{
return time_span<counter_type>(first.m_stamp - second.m_stamp);
}
private:
value_type m_stamp;
}
The time_span template is as follows (time_span.h):
template<typename counter_type>
class time_span
{
public:
// TYPES
typedef counter_type counter_type;
typedef typename counter_type::value_type value_type;
/* rest removed for sake of this post */
}
The C++ Builder compiler appears to not like the line: friend time_span operator-(const time_stamp &first, const time_stamp &second)
I'm new to templates and this syntax escapes me or at least the compiler error I can't make sense of. It appears, to me, that there are no default argument values despite the compiler saying so. I'm interpreting the error message as saying const time_stamp & is a default value when it looks to me like a passed reference of type time_stamp.
Thanks for reading & replying. Help understanding as well as fixing is most appreciated.
--- EDIT:
If I re-structure the call above as follows:
friend time_span<counter_type> operator-( (const time_stamp<counter_type>& first, const time_stamp<counter_type>& second) );
and outside the class definition, I describe the function:
template<typename counter_type>
time_span<counter_type> operator-( (const time_stamp<counter_type>& first, const time_stamp<counter_type>& second) )
{
return time_span<counter_type>(first.m_stamp-second.m_stamp);
}
I then get this error:
[BCC32 Error] time_stamp.hpp(56): E2082 '-(int (*)(const time_stamp &,const time_stamp &))' must be a member function or have a parameter of class type
()parentheses in both thefrienddeclaration and the definition. - aschepler