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

  • Home
  • SEARCH
  • 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 7673189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:27:13+00:00 2026-05-31T16:27:13+00:00

Using VS 2008, the target environment is Windows CE with an ARM processor if

  • 0

Using VS 2008, the target environment is Windows CE with an ARM processor if that makes a difference. I know that the compiler we are using is kind of dated as well…

The basic problem I am having is that I am trying to make my own iterator for a map wrapper I wrote and overloading the operator->() is giving me trouble. This is the bit of code that is giving me issues:

const pair<wstring, PropertyMap*>* ObjectMapIterator::operator->() const
{
    return &*m_MapIter;
}

I know that it doesn’t really make sense to return a const variable usually, but I can’t seem to figure out how to do this in a way that lets the rest of the program be const-correct without doing that.

The error I get is this:

error C2440: ‘return’ : cannot convert from ‘const
std::pair<_Ty1,_Ty2> *’ to ‘const std::pair<_Ty1,_Ty2> *’

The header for this iterator looks like this:

class ObjectMapIterator
{
public:
    ObjectMapIterator(const ObjectMap& rObjectMap);
    const ObjectMapIterator& operator++(int rhs);
    std::pair<std::wstring, PropertyMap*> operator*() const;
    const std::pair<std::wstring, PropertyMap*>* operator->() const;
    bool isDone() const;

private:
    const std::map<std::wstring, PropertyMap*>* m_pPropertyMaps;
    std::map<std::wstring, PropertyMap*>::const_iterator m_MapIter;
};

As you can see, both the m_MapIter and the return value of the overloaded operator are the same… I took all of the const statements out of the .h and .cpp files for this part of the project and recompiled with the same error, so I don’t think this is an issue with that.

If I do something like this instead, the program will compile:

const pair<wstring, PropertyMap*>* ObjectMapIterator::operator->() const
{
    const pair<wstring, PropertyMap*>* returnVal = new pair<wstring, PropertyMap*>(*m_MapIter);
    return returnVal;
}

I know that doing that would lead to a memory leak, I didn’t put it into a smart pointer just to save space for posting this.

Here is the whole .cpp file in case you might find that relevant:

#include "stdafx.h"
#include "ObjectMap.h"

using namespace std;

ObjectMapIterator::ObjectMapIterator(const ObjectMap& rObjectMap)
    :m_pPropertyMaps(&(rObjectMap.m_PropertyMaps)),
     m_MapIter(m_pPropertyMaps->begin())
{}

const ObjectMapIterator& ObjectMapIterator::operator++(int rhs)
{
    if(m_MapIter != m_pPropertyMaps->end())
    {
        m_MapIter++;
        return *this;
    }
    else
    {
        return *this;
    }
}

pair<wstring, PropertyMap*> ObjectMapIterator::operator*() const
{
    return *m_MapIter;
}

const pair<wstring, PropertyMap*>* ObjectMapIterator::operator->() const
{
    return &*m_MapIter;
}

bool ObjectMapIterator::isDone() const
{
    return m_MapIter == m_pPropertyMaps->end();
}

The ObjectMapIterator definition is inside of the ObjectMap.h file. So I am not forgetting to include ObjectMapIterator.

I’ve been scratching my head over this for too long. Please let me know if you figure anything out. Thanks!

  • 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-31T16:27:15+00:00Added an answer on May 31, 2026 at 4:27 pm

    std::map::const_iterator returns a temporary, not a reference, so you are trying to take address of that temporary and return it.

    Why not simply return pair by value?

    std::pair<std::wstring, PropertyMap*>* ObjectMapIterator::operator->() const
    {
        return *m_MapIter;
    }
    

    Actually, if your operator will return std::map::const_iterator::pointer, as
    std::map::const_iterator::operator->() does, everything will be ok:

    std::map<std::wstring, PropertyMap*>::const_iterator::pointer operator->() const
    {
    return &*m_MapIter;
    }
    

    Also, as far as value, returned by std::map::const_iterator::operator->() is implementation defined, may be it would be better to use

    auto operator->() const -> decltype(m_MapIter.operator->())
    {
    return (m_MapIter.operator->());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using VS 2008 to develop an application that uses a .dll with
I have created a Windows Form Application using Visual C# 2008 Express Edition with
I am building a Windows Application using Visual Studio 2008. For the forms (2
Is there any way to create a Windows Installer using Visual Studio 2008 to
I'm using Visual Studio 2008 to target .NET 2 so a portion of our
VS 2008 I have developed a device application that runs on windows mobile 5.
Using c#, how do I copy a symbolic link in Windows Vista,7,2008. When I
Using VS2005/2008 as a resource editor, one of the options in the Add Resource
Using MSSQL 2008 and XQUERY Consider the following XML stored in a table: <ROOT>
I am using VS 2008 with SP1 and the IE 8 beta 2. Whenever

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.