Character variables and addresses
Code:
#include <iostream>
using namespace std;
class Multitudinous
{
private:
int int1;
float float1;
public:
float float2;
double double1;
void showMap();
friend int main();
protected:
char char1;
private:
int int2;
double double2;
char char2;
public:
long long1;
double double3;
protected:
int int3, int4;
char char3, char4;
private:
long long2;
double double4;
public:
float float3, float4;
protected:
char char5, char6, char7;
};
void Multitudinous::showMap()
{
cout << "int1: " << &int1 << endl << "float1: " << &float1 << endl;
cout << "float2: " << &float2 << endl << "double1: " << &double1 << endl;
cout << "char1: " << &(char1) << endl << "int2: " << &int2 << endl;
cout << "double2: " << &double2 << endl << "char2: " << &(char2)<< endl;
cout << "long1: " << &long1 << endl << "double3: " << &double3 << endl;
cout << "int3: " << &int3 << endl << "int4: " << &int4 << endl;
cout << "char3: " << &(char3) << endl << "char4: " << &(char4) << endl;
cout << "long2: " << &long2 << endl << "double4: " << &double4 << endl;
cout << "float3: " << &float3 << endl << "float4: " << &float4 << endl;
cout << "char5: " << &(char5) << endl << "char6: " << &(char6) << endl;
cout << "char7: " << &(char7) << endl;
}
int main()
{
Multitudinous c1;
c1.showMap();
char* point = &(c1.char1);
cout << "char1: " << point << endl;
point = &(c1.char2);
cout << "char2: " << point << endl;
point = &(c1.char3);
cout << "char3: " << point << endl;
point = &(c1.char4);
cout << "char4: " << point << endl;
point = &(c1.char5);
cout << "char5: " << point << endl;
point = &(c1.char6);
cout << "char6: " << point << endl;
point = &(c1.char7);
cout << "char7: " << point << endl;
return 0;
}
The program above is meant to simply print out the addresses of the data members of the object, in order to gain some insight into memory allocation within classes.
The problem is that the member function showMap() seems to be unable to print out the addresses of the character variables of the object, and I have no idea why this is the case. Instead of addresses, the output takes the form of a string of seemingly random characters.
Can anyone explain why this is happening and how to fix it?