C
Christian Christmann
Hi,
here is my small program:
Header file:
Class myClass
{
public:
void function();
list< pair< Object1*, Object1*> > getList() const;
...
private:
typedef std:air< Object1*, Object1* > mPairType;
list< mPairType > myList;
...
};
And the source file:
list< pair< Object1*, Object1*> > myClass:getList() const
{
return myList;
}
void myClass::function()
{
typedef std:air< Object1*, Object1* > myType;
list< myType>::const_iterator it = getList().begin();
for ( ; it != getList().end(); ++it )
{
std:air< Object1*, Object1* > myPairs = (*it);
}
}
....
When I run this program, I get segmentation faults in line
"std:air< Object1*, Object1* > myPairs = (*it);".
When I instead replace the function getList() by a direct
access to member "myList", i.e.:
void myClass::function()
{
typedef std:air< Object1*, Object1* > myType;
list< myType>::const_iterator it = myList.begin();
for ( ; it != myList.end(); ++it )
{
std:air< Object1*, Object1* > myPairs = (*it);
}
}
Everything works fine.
I don't understand why the return value of getList() [ returns the STL list ]
is not the same as a direct access to the private class member "myList".
What do I have to change to access the private member function "myList"
by the public class function getList() ?
I appreciate any help.
Thank you.
Chris
here is my small program:
Header file:
Class myClass
{
public:
void function();
list< pair< Object1*, Object1*> > getList() const;
...
private:
typedef std:air< Object1*, Object1* > mPairType;
list< mPairType > myList;
...
};
And the source file:
list< pair< Object1*, Object1*> > myClass:getList() const
{
return myList;
}
void myClass::function()
{
typedef std:air< Object1*, Object1* > myType;
list< myType>::const_iterator it = getList().begin();
for ( ; it != getList().end(); ++it )
{
std:air< Object1*, Object1* > myPairs = (*it);
}
}
....
When I run this program, I get segmentation faults in line
"std:air< Object1*, Object1* > myPairs = (*it);".
When I instead replace the function getList() by a direct
access to member "myList", i.e.:
void myClass::function()
{
typedef std:air< Object1*, Object1* > myType;
list< myType>::const_iterator it = myList.begin();
for ( ; it != myList.end(); ++it )
{
std:air< Object1*, Object1* > myPairs = (*it);
}
}
Everything works fine.
I don't understand why the return value of getList() [ returns the STL list ]
is not the same as a direct access to the private class member "myList".
What do I have to change to access the private member function "myList"
by the public class function getList() ?
I appreciate any help.
Thank you.
Chris