So I'm designing a Dictionary for one of my classes and I'm having quite a bit of trouble when I try to return a Position, which is just a pointer to a pair<string, Element>.

I can't quite figure it out -- I suspect its something I did with my actual position class in defining it, but the class itself has three member functions (key, element, isNull) and one member variable (pair<string, Element>* mPtr).

Here is my find function -- it finds everything just fine -- but when I try to return it gives me an error message saying unable to access a certain address. Hopefully I'm just doing something absolutly stupid. but anyway -- here it is.

Position Dictionary::find (string in)
{
     Position result;
     pair<string, Element>* tmp;
     tmp = new pair<string, Element>;
     unsigned int temp = 0;
     int check = 0;

     result.mPtr = tmp;

     while (temp < this->mArray.size() && check == 0)
     {
         if(this->mArray[temp].first == in)
         {
             result.mPtr->first = this->mArray[temp].first;
             result.mPtr->second = this->mArray[temp].second;
             check++;
         }
         else
         {
             temp++;
         }
     }

     if(check == 0)
     {
         result.mPtr = NULL;
         return(result);
     }
     else
     {
         return(result);
     }
}

Also here are my position class definitions

Position::Position(void)
{
    this->mPtr = NULL;
}

Position::Position(const Position & in)
{
    this->mPtr->first = in.mPtr->first;
    this->mPtr->second = in.mPtr->second;

}

Element& Position::element(void) const
{
    return(this->mPtr->second);
}

Position& Position::operator =(const Position & in)
{
    this->mPtr->first = in.mPtr->first;
    this->mPtr->second = in.mPtr->second;
    return(*this);
}

const string& Position::key(void) const
{
    return(this->mPtr->first);
}

bool Position::isNull (void)
{
    if(this->mPtr == NULL)
    {
        return(true);
    }
    else
    {
        return(false);
    }
}

Also -- sorry if this is in the wrong forum -- new to the site -- thanks for any help!!

This article has been dead for over six months. Start a new discussion instead.