i'm learning c++ and i'm experimenting with different scenarios.So i wanted to do a shallow copy a class so this is what i came up with -
#include <iostream>
class not_dynamic
{
private:
int data;
public:
not_dynamic(int temp_data = 200) //constructor
:data(temp_data)
{
std::cout << "constructor initialized" << std::endl;
}
not_dynamic(const not_dynamic& source)
:data(source.data)
{
std::cout << "copy constructor initialized" << std::endl;
}
void get_info()
{
std::cout << data << " " << &data << std::endl;
}
};
int main()
{
not_dynamic v{ 100 };
v.get_info();
not_dynamic jackie{ v };
jackie.get_info();
}
for this i get the following result -
constructor initialized
100 00EFFBD4 // 100 is the value in data and 00EFFBD4 is address of data
copy constructor initialized
100 00EFFBC8 // same as above
but as i recall in shallow copy all the same instances of different object(both objects are same) should have same memory address, but in this case its same.
I'm really confused.Can you guys help me??
Thanks