class Closed_chain {
public:
private:
int element;
int* pt_element;
}
with constructor: Closed_chain(int element, int* pt_element):element(element), pt_element(pt_element){}
In the main, how can I set the default value of the copnstructor in order to allows me to create a single element chain that contains a pointer that point to its own element.
class ClosedChain
{
private:
int Element;
int *PtrElement;
public:
ClosedChain();
~ClosedChain(){};
};
ClosedChain::ClosedChain()
{
Element = 5;
*PtrElement = Element;
}
Is this what you are shooting for? The pointer really doesn't do anything other than point to the spot where Element is and gets the value. So, Element would be 5 and *PtrElement would be 5 also. Unless you wanted it to get the location of Element then it would be different. This code will not compile correctly because it is not a whole section of code. This is only the class definition and constructor. In the constructor you can make Element and *PtrElement equal to anything you wish. If Element variable changes than in theory *PtrElement should change as well.