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 7419827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:08:15+00:00 2026-05-29T08:08:15+00:00

How do I go about overloading a template class like below? template <class T>

  • 0

How do I go about overloading a template class like below?

template <class T>
const_iterator& List<T>::const_iterator::operator++()
{
  current = current->next;
  return *this;
}

template <class T>
const_iterator List<T>::const_iterator::operator++(int)
{
  const_iterator old = *this;
  ++( *this );
  return old;
}

I am getting errors like below:

List.cpp:17: error: expected constructor, destructor, or type conversion before ‘&’ token
List.cpp:23: error: expected constructor, destructor, or type conversion before ‘List’
List.cpp:30: error: expected constructor, destructor, or type conversion before ‘&’ token
List.cpp:35: error: expected constructor, destructor, or type conversion before ‘List’
  • 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-29T08:08:16+00:00Added an answer on May 29, 2026 at 8:08 am
    template <class T>
    typename List<T>::const_iterator& List<T>::const_iterator::operator++()
    

    At the time the return type is specified, you’re not inside the so-called lexical scope of List<T>. And since there is no type const_iterator in the enclosing scope, you get an error (though that one could manifest itself a little bit better, IMHO).

    Another option for C++11 might be a trailing return type:

    template<class T>
    auto List<T>::const_iterator::operator++()
        -> const_iterator&
    {
      // ...
    }
    

    However, the best idea would be to just define these things inline in the class itself. Do you have a special reason for the out-of-class definitions?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I asked this question about overloading the copy constructor and assignment operator with template
I would like to have the mutators (setters) in my class to return this
I have a question about the return value of operator overloading in C++. Generally,
I've always wondered about this for a bit, but why is operator overloading not
i'm not sure if what im talking about is an operator overloading question. is
This is an ASP.Net 2.0 web app. The Item template looks like this, for
From the C++ standard (ISO/IEC 14882:2003(E)), §12.5.4, about overloading operator delete : If a
I have some problems overloading operators with template members and using make_pair: class MyArchive
I see questions on SO every so often about overloading the comma operator in
I've been reading about overloading new and delete (and related topics like placement new/delete).

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.