-
December 1st, 2010, 08:59 AM
#1
Using getter and setter in Class
Basically I'm pretty new to C++, I'm trying to implement the getting and setter function within a class data member using a struct, I got no idea where to start. I've looked around the internet but there's nothing that I can see. Here is the code: (Can you keep any explanations extremely simple)
<code>
#include "stdafx.h"
#include <fstream>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <cstring>
#include <string>
#include <vector>
#include <sstream>
using namespace std;
#define _CRTDBG_MAP_ALLOC
#include <crtdbg.h>
struct SEmployee
{
string name;
int id;
};
class CPayRoll
{
private:
SEmployee* mp;
public:
CPayRoll( string name, int id );
~CPayRoll();
void SetDetails( string name, int id );
void GetDetails( string& name, int& id );
};
CPayRoll::CPayRoll( string name, int id )
{
mp = new SEmployee;
mp->name = name;
mp->id = id;
}
CPayRoll::~CPayRoll()
{
delete (mp);
}
void SetDetails( string name, int id )
{
}
void GetDetails( string& name, int& id )
{
}
int main()
{
CPayRoll* Olly = new CPayRoll("Olly",100);
cout << endl;
system("pause");
delete(Olly);
_CrtDumpMemoryLeaks();
}
</code>
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|