Hi fellow coders,
I have a problem that I need assistance with.
Consider this class in intset.h:
Constructor implementation in intset.cpp
Now when I use the member functions, I want to create a third set which is the union of the sets or intersection of the sets which are passed as arguments. But obviously when the function exits it will destroy the third set so I'm left with the so-called 'dangling pointer'. If I declare the third set as static then I end up modifying the same third set everytime I call the functions so the original third set is lost. I don't want to create a third object in main() and assign the result of a intersection or union to it. I want to return a pointer of the newly created third set and assign it to a pointer in main().
ie.
Can someone please help? If I can't do what I'm doing above can someone out there tell me why and/or suggest any alternative method (without creating the third object in main() ofcourse).
Thanks in advance guys!
Kunal.
I have a problem that I need assistance with.
Consider this class in intset.h:
Code:
class CIntSet
{
public:
CIntSet();
~CIntSet();
CIntSet* intersect( CIntSet* is1, CIntSet* is2 );
CIntSet* unionofSets( CIntSet* is1, CIntSet* is2 );
private:
int* intSet;
};
Constructor implementation in intset.cpp
Code:
CIntSet::CIntSet()
{
intSet = new int[5];
// initialise intset[]
}
Now when I use the member functions, I want to create a third set which is the union of the sets or intersection of the sets which are passed as arguments. But obviously when the function exits it will destroy the third set so I'm left with the so-called 'dangling pointer'. If I declare the third set as static then I end up modifying the same third set everytime I call the functions so the original third set is lost. I don't want to create a third object in main() and assign the result of a intersection or union to it. I want to return a pointer of the newly created third set and assign it to a pointer in main().
ie.
Code:
main()
{
CIntSet* intSetPtr = intSetPtr->intersect( is1, is2 );
}
Thanks in advance guys!
Kunal.