Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3752184
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T09:12:18+00:00 2026-05-19T09:12:18+00:00

I’m trying to port some Visual C++ (VS2005) code so that it will compile

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T09:12:19+00:00Added an answer on May 19, 2026 at 9:12 am

    [Replacing my previous answer!]

    This is probably related to http://www.parashift.com/c++-faq/templates.html#faq-35.16 .

    Since the function you want to define is in fact a template function (it depends on counter_type), you should declare it before the friend declaration, and then declare a function template instantiation to be the friend:

    // time_stamp.h
    #include "time_span.h"
    template<typename counter_type> class time_stamp;
    template<typename counter_type> time_span<counter_type> operator-(
        const time_stamp<counter_type>&, const time_stamp<counter_type>& );
    
    template<typename counter_type>
    class time_stamp
    {
      //...
        friend time_span<counter_type> operator- <> (
            const time_stamp<counter_type>&, const time_stamp<counter_type>&);
    };
    
    template<typename counter_type>
    inline 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);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I am trying to loop through a bunch of documents I have to put
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have some data like this: 1 2 3 4 5 9 2 6

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.