Hi
I'm new to C++ but have some experience with Java. To practice using C++, I've been trying to translate some old Java programs I've written to see how the languages compare.
I've created two basic C++ classes - 'Worker' and 'Job' and what I'm trying to do is to make them hold references to each other i.e. each worker does a job and holds a reference to it. When I did this in Java I simply implemented a User-Defined Type but I have not been able to achieve this in C++:
Code:
public class Worker {
private String name;
private String address;
private String telephone; // Java Attributes
private Job job;
.........etc.
I've managed to get the name, address and telephone attributes to work in C++, with getters/setters and constructor etc. but no luck with job.
I've used #include "job.hpp" which compiles ok, but then will not recognise '"Job' as a type.
Code:
#include <cstdlib>
#include <iostream>
#include <string>
#include "job.hpp"
using namespace std;
//worker.cpp
class Worker {
public:
//constructor
Worker (string name, string address, string telephone, Job job);
//destructor
~Worker();
//setters
void setName (string name);
void setAddress (string address);
void setTelephone (string telephone);
void setJob (Job job);
//getters
string getName();
string getAddress();
string getTelephone();
Job getJob();
private:
string name;
string address;
string telephone;
Job job
};
//constructor definitions
Worker::Worker(string name, string address, string telephone, Job job)
{
this -> name = name;
this -> address = address;
this -> telephone = telephone;
this -> job = job;
} etc...
If anyone could offer some advice or point me in the direction of a good tutorial It'd be much appreciated!
Many thanks
Gak