Dear Sir/madam,

I am working on Solaris 8.
dbx is showing memory access error in the following line:

template<class keyType_t, class dataType_t>
int WrapperC<keyType_t, dataType_t>::insert(keyType_t keyVal,
dataType_t& info_t )
{
    pair<map<keyType_t,dataType_t>::iterator,bool> retItor;
    retItor = subsInfoMap_obj.insert( pair<keyType_t, dataType_t>(keyVal, info_t
 ) );
........
};

WrapperC class is derived from an abstract class which is as follows:

</code>
template<class keyType_t, class dataType_t>
class ContAbsC
{
    public:
        ContAbsC( keyType_t, dataType_t );
        virtual int insertElementInto( keyType_t, dataType_t& ) = 0 ;
    protected:
        keyType_t keyValue;
        dataType_t info;
};

template<class keyType_t, class dataType_t>
class WrapperC : public ContAbsC<keyType_t, dataType_t>
{

    protected:
        map<keyType_t, dataType_t> Map_obj;
        typedef map<keyType_t, dataType_t> InfoMap;
        typename typedef map<keyType_t, dataType_t>::iterator InfoMap_itor;
        typedef typename pair<typename map<keyType_t,dataType_t>::iterator,bool> Map_pairItor;
    public:
        WrapperC();
        WrapperC(dataType_t);
        WrapperC( keyType_t, dataType_t);
        virtual int insert( keyType_t, dataType_t& ) ;
        
        //Copy constructor
        WrapperC( const WrapperC& Wrapper_o );
        //Assignment Operator Overlaoding
        WrapperC& operator= ( const WrapperC& mapWrapper_o );
};

dbx is showing similar access errors in lot of other places also. Please guide me to solve this problem.

Regards,
sham

Member Avatar for jencas

Can't find subsInfoMap_obj

And please: use correct code tags!! Thank you!

Sorry for that.
Please find the complete code here:

#include<iostream>
#include<map>
using namespace std;

struct MsgS
{
       unsigned long key;
       int element;
};

template<class keyType_t, class dataType_t>
class AbsC
{
    public:
        AbsC();
        AbsC( keyType_t, dataType_t );
        virtual int insert( keyType_t, dataType_t& ) = 0 ;
        virtual int remove( keyType_t, dataType_t* ) = 0 ;
        virtual int search( keyType_t, dataType_t* ) = 0 ;
        ~AbsC();

    protected:
        keyType_t keyValue;
        dataType_t info;

};

template<class keyType1_t, class dataType1_t>
class WrapperC : public AbsC<keyType1_t, dataType1_t> 
{

    protected:
        map<keyType1_t, dataType1_t> InfoMap_obj;
        typedef map<keyType1_t, dataType1_t> InfoMap;
        typename typedef map<keyType1_t, dataType1_t>::iterator InfoMap_itor;
        typedef typename pair<typename map<keyType1_t,dataType1_t>::iterator,bool> InfoMap_pairItor;
    public:
        WrapperC( keyType1_t arg1, dataType1_t arg2) ;

        virtual int insert( keyType1_t keyVal, dataType1_t& info_t) 
        {
                pair<map<keyType1_t,dataType1_t>::iterator,bool> retItor;
                retItor = InfoMap_obj.insert( pair<keyType1_t, dataType1_t>(keyVal, info_t ) );

                if ( retItor.second == false )
                {
                        cout<<"\n Element alread exists";
                        return (-1);
                }
                return (1);
        };

        virtual int remove( keyType1_t keyVal, dataType1_t* info_tp) 
        {
                InfoMap_itor retItor;
                retItor =  InfoMap_obj.find(keyVal) ;
                if(retItor == InfoMap_obj.end())
                {
                        cout <<"\n key not found";
                        info_tp = NULL;
                        return (-1);
                }
                *info_tp = retItor->second;
                InfoMap_obj.erase( InfoMap_obj.find(keyVal) );
                return (1);
        };

        virtual int search( keyType1_t keyVal, dataType1_t* info_tp) 
        {
                //dataType_t infoRet;
                InfoMap_itor retItor;
                retItor = InfoMap_obj.find( keyVal );
                if(retItor == InfoMap_obj.end() )
                {
                        cout<<"\n key not found";
                        cout << endl << "search key: \"" << keyVal << "\"" << endl;
                        //displayDataFrom();
                        info_tp = NULL;
                        return ( -1 );
                }
                *info_tp = retItor->second;
                return( 1 );
        };
        ~WrapperC(){};

        //Copy constructor 
        WrapperC( const WrapperC& mapWrapper_o )
        {
                if( &mapWrapper_o != NULL ) 
                {
                        this->subsInfoMap_obj = mapWrapper_o.InfoMap_obj ;
                }
        };
        //Assignment Operator Overlaoding
        WrapperC& operator= ( const WrapperC& mapWrapper_o )
        {
                if( ( this != &mapWrapper_o ) && ( &mapWrapper_o != NULL ) )
                {
                        this->InfoMap_obj = mapWrapper_o.InfoMap_obj ;
                        this->noOfElem_ul = mapWrapper_o.noOfElem_ul ;
                }
                return ( *this ) ;
        };
};

template<class keyType_t, class dataType_t>
AbsC<keyType_t, dataType_t>::AbsC()
{
}

template<class keyType_t, class dataType_t>
AbsC<keyType_t, dataType_t>::AbsC( keyType_t argkeyValue, dataType_t info_t)
{
    info = info_t;
    keyValue = argkeyValue;
}

template<class keyType_t, class dataType_t>
AbsC<keyType_t, dataType_t>::~AbsC()
{
}

template<class keyType1_t, class dataType1_t>
WrapperC<keyType1_t, dataType1_t>::WrapperC( keyType1_t key_t, dataType1_t info_t):AbsC( key_t, info_t)
{
}

int main()
{
        struct MsgS msgS;
        struct MsgS* msgR;
        msgR = new struct MsgS;
        msgS.key = 123456;
        msgS.element = 1;
        WrapperC<unsigned long, struct MsgS> objS(msgS.key, msgS);
        int b = objS.insert( msgS.key, msgS);
        //int b = objS.insert( msgS.key, msgS.key);
        // adding 2 element
        msgS.key = 123454;
        msgS.element = 2;
        b = objS.insert( msgS.key, msgS);
        //remove elem
        b = objS.remove(12, msgR);
        if ( b == 1 )
                cout<<"\n ret value for remove elem "<<msgR->key << "\t" << msgR->element<<endl;
        b = objS.remove(123456, msgR);
        if ( b == 1 )
                cout<<"\n ret value for remove elem "<<msgR->key << "\t" << msgR->element<<endl;
        b = objS.search(78912, msgR);
        if ( b ==1 )
                cout<<"\n ret value for search elem "<<msgR->key << "\t" << msgR->element<<"\n";
        b = objS.search(123454, msgR);
        if ( b == 1 )
                cout<<"\n ret value for search elem "<<msgR->key << "\t" << msgR->element<<endl;
        return 1;
}

The line which is showing access error is:

" virtual int insert( keyType1_t keyVal, dataType1_t& info_t)
    {
           pair<map<keyType1_t,dataType1_t>::iterator,bool> retItor;"

dbx report is as follows:

<rtc> Read from uninitialized (rui):
Attempting to read 4 bytes at address 0xffbee8c8
    which is 192 bytes above the current stack pointer
=>[1] __rwstd::__rb_tree<unsigned long,std::pair<const unsigned long,MsgS>,__rwstd::__select1st<std:
:pair<const unsigned long,MsgS>,unsigned long>,std::less<unsigned long>,std::allocator<std::pair<con
st unsigned long,MsgS> > >::iterator::iterator(0xffbee93c, 0xffbee8c8, 0x2, 0xfb8, 0xfe960c00, 0xff8
), at 0x305f4
  [2] std::pair<__rwstd::__rb_tree<unsigned long,std::pair<const unsigned long,MsgS>,__rwstd::__sele
ct1st<std::pair<const unsigned long,MsgS>,unsigned long>,std::less<unsigned long>,std::allocator<std
::pair<const unsigned long,MsgS> > >::iterator,bool>::pair(this = 0xffbee93c), line 106 in "utility"
  [3] WrapperC<unsigned long,MsgS>::insert(this = 0xffbeea0c, keyVal = 123456U, info_t = STRUCT), li
ne 42 in "sample.cc"
  [4] main(), line 138 in "sample.cc"

<rtc> Read from uninitialized (rui):
Attempting to read 4 bytes at address 0xffbee8c8
    which is 192 bytes above the current stack pointer
=>[1] __rwstd::__rb_tree<unsigned long,std::pair<const unsigned long,MsgS>,__rwstd::__select1st<std:
:pair<const unsigned long,MsgS>,unsigned long>,std::less<unsigned long>,std::allocator<std::pair<con
st unsigned long,MsgS> > >::iterator::iterator(0xffbee93c, 0xffbee8c8, 0x2, 0xfb8, 0xfe960c00, 0xff8
), at 0x305f4
  [2] std::pair<__rwstd::__rb_tree<unsigned long,std::pair<const unsigned long,MsgS>,__rwstd::__sele
ct1st<std::pair<const unsigned long,MsgS>,unsigned long>,std::less<unsigned long>,std::allocator<std
::pair<const unsigned long,MsgS> > >::iterator,bool>::pair(this = 0xffbee93c), line 106 in "utility"
  [3] WrapperC<unsigned long,MsgS>::insert(this = 0xffbeea0c, keyVal = 123454U, info_t = STRUCT), li
ne 42 in "sample.cc"
  [4] main(), line 143 in "sample.cc"
Member Avatar for jencas

Your code works for me with VS2008

Your code works for me with VS2008

Thanks for your time jencas. It works for me also. But, my debugger(dbx) shows memory access errors whose report is in my orevious post. I am not able to figure out why dbx is showing that error.

Member Avatar for jencas

I stepped through the whole main() without problems.

This looks suspicious to me:

pair<map<keyType1_t,dataType1_t>::iterator,bool> retItor;
retItor = InfoMap_obj.insert( pair<keyType1_t, dataType1_t>(keyVal, info_t ) );

What about this additional bool?

Hey shamiliroy, did you notice the following sentence just below your first post of this thread:

Last edited by ~s.o.s~ : 17 Hours Ago at 18:49. Reason: Added code tags, learn to use them.

I want to felicitate you that you've at least tried to use code tags (in your second post), but I would suggest you to read this one more time, to learn how to use them correctly in your future posts.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.