Click here to Skip to main content
15,910,787 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: string trim and toupper/tolower Pin
George_George4-Sep-08 21:58
George_George4-Sep-08 21:58 
GeneralRe: string trim and toupper/tolower Pin
Nibu babu thomas4-Sep-08 22:19
Nibu babu thomas4-Sep-08 22:19 
GeneralRe: string trim and toupper/tolower Pin
George_George4-Sep-08 22:47
George_George4-Sep-08 22:47 
AnswerRe: string trim and toupper/tolower Pin
Naveen4-Sep-08 20:10
Naveen4-Sep-08 20:10 
GeneralRe: string trim and toupper/tolower Pin
George_George4-Sep-08 20:11
George_George4-Sep-08 20:11 
AnswerRe: string trim and toupper/tolower Pin
Rajesh R Subramanian4-Sep-08 20:41
professionalRajesh R Subramanian4-Sep-08 20:41 
GeneralRe: string trim and toupper/tolower Pin
George_George4-Sep-08 21:39
George_George4-Sep-08 21:39 
QuestionClass initialization and memory allocation Pin
Christian Flutcher4-Sep-08 19:11
Christian Flutcher4-Sep-08 19:11 
#include <iostream.h>
class Person
{
        string name;
        int age;
public:
        string GetName(void);
        int GetAge(void);
        Person(string personName,int personAge);
        Person(void);
};

int main()
{
        Person *person = new Person("Chris",30);
        cout << person->GetName() << endl;
        cout << person->GetAge() << endl;

        Person anotherPerson;
        cout << anotherPerson.GetName() << endl;
        cout << anotherPerson.GetAge() << endl;

        delete person;
        return 0;
}

string Person::GetName()
{
        return name;
}
int Person::GetAge()
{
        return age;
}
Person::Person(string personName,int personAge)
{
        name = personName;
        age = personAge;
}
Person::Person()
{
        name = "Unknown";
        age = 0;
}
I used to program using C# and learning C++ now. I have some doubts on the above shown program.

1 - Person anotherPerson is declared but not initialized. But still calls to anotherPerson.GetName() worked. How this is happening?

2 - Is there any difference when allocating memory for *person and anotherPerson?

3 - I know we should delete the pointer variables to claim memory. But AFAIK, there is no need to delete the anotherPerson variable. How it gets removed from memory?
AnswerRe: Class initialization and memory allocation [modified] Pin
_AnsHUMAN_ 4-Sep-08 19:27
_AnsHUMAN_ 4-Sep-08 19:27 
GeneralRe: Class initialization and memory allocation Pin
Christian Flutcher4-Sep-08 19:40
Christian Flutcher4-Sep-08 19:40 
GeneralRe: Class initialization and memory allocation Pin
Cedric Moonen4-Sep-08 19:57
Cedric Moonen4-Sep-08 19:57 
GeneralRe: Class initialization and memory allocation Pin
Christian Flutcher4-Sep-08 20:20
Christian Flutcher4-Sep-08 20:20 
GeneralRe: Class initialization and memory allocation Pin
Cedric Moonen4-Sep-08 20:27
Cedric Moonen4-Sep-08 20:27 
GeneralRe: Class initialization and memory allocation Pin
Christian Flutcher4-Sep-08 20:29
Christian Flutcher4-Sep-08 20:29 
GeneralRe: Class initialization and memory allocation Pin
_AnsHUMAN_ 4-Sep-08 19:58
_AnsHUMAN_ 4-Sep-08 19:58 
GeneralRe: Class initialization and memory allocation Pin
Rajesh R Subramanian4-Sep-08 20:16
professionalRajesh R Subramanian4-Sep-08 20:16 
GeneralRe: Class initialization and memory allocation Pin
_AnsHUMAN_ 4-Sep-08 20:29
_AnsHUMAN_ 4-Sep-08 20:29 
GeneralRe: Class initialization and memory allocation Pin
Naveen4-Sep-08 20:23
Naveen4-Sep-08 20:23 
GeneralRe: Class initialization and memory allocation Pin
Rajesh R Subramanian4-Sep-08 20:00
professionalRajesh R Subramanian4-Sep-08 20:00 
GeneralRe: Class initialization and memory allocation Pin
Christian Flutcher4-Sep-08 20:17
Christian Flutcher4-Sep-08 20:17 
GeneralRe: Class initialization and memory allocation Pin
Cedric Moonen4-Sep-08 20:25
Cedric Moonen4-Sep-08 20:25 
GeneralRe: Class initialization and memory allocation Pin
Rajesh R Subramanian4-Sep-08 20:25
professionalRajesh R Subramanian4-Sep-08 20:25 
GeneralRe: Class initialization and memory allocation Pin
Christian Flutcher4-Sep-08 20:31
Christian Flutcher4-Sep-08 20:31 
GeneralRe: Class initialization and memory allocation Pin
Rajesh R Subramanian4-Sep-08 20:42
professionalRajesh R Subramanian4-Sep-08 20:42 
AnswerRe: Class initialization and memory allocation Pin
santhoshv844-Sep-08 19:27
santhoshv844-Sep-08 19:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.