I'm having a bit of a problem with a group project. We're supposed to use linked lists in it and I've already created classes for the nodes for the linked lists. The only problem is that I need to make the class point to itself but I'm not sure how to write the accessor and mutator code or how to implement them properly. I'll post the code below. can anyone help?

#ifndef PROCESSEDPAYROLL
#define PROCESSEDPAYROLL
#include "DeptRates.h"
#include "EmployeePayroll.h"
#include <iostream>

using namespace std;

//creation of class ProcessedPayroll

class ProcessedPayroll:public EmployeePayroll: public DeptRates
{
private:
	float RegularPay;
	float OvertimePay;
	float GrossPay;
	ProcessedPayroll* ProcssPrll;//pointer to the structure to make it a node in the linked list
public:
	ProcessedPayroll();
	float getRegularPay();
	float getOvertimePay();
	float getGrossPay();
	ProcessedPayroll* getProcsPrll
	void CalculateRegularPay(float, float, float);
	void CalculateGrossPay(float, float, float);
	void CalculateOvertimeHrs(float, float);
	void CalculateOvertimePay(float, float);
	
	void virtual SaveRecord(); //saves record to the file.
	void virtual SaveEmployee();
	
};
#endif

I'm not sure what the question is.

You declare a pointer to an object of the appropriate type on line 17, in most linked lists I've seen, it is usually named "next" but other than that I don't see a problem.

You do appear to be declaring one on line 23 as well, or was that supposed to be an accessor?

If is were my implementation the private member would be ProcessedPayroll* pNext; and the accessor would be ProcessedPayroll * getNext() and the mutator void setNext(ProcessedPayroll * next) For the rest of the linked list, you need to have a "head" pointer that either points to NULL if the list is empty, or the first object in the list. The last object on the list will have its "next" pointer point to NULL.

How things are added to the linked list depends on the importance of ordering to the list. For a standard linked list, it is easiest to add elements at the head, but then when the data is accessed in the normal fashion, the data is in the opposite order from how it was added. (The last added would be the first seen.)

If the elements are to be added to the end of the linked list to maintain the order, you must either iterate to the end of the list every time you want to add one, or maintain a pointer to the "tail" (last object in the list -- NULL if the list is empty).

I hope this was useful or that you've already solved it yourself :)

Thanks for the reply. I've been getting some weird errors in the program and I changed the name recently so that it makes more sense and stuff...but I'm still a bit unsure about the errors and all of that.

I'm not sure what the question is.

You declare a pointer to an object of the appropriate type on line 17, in most linked lists I've seen, it is usually named "next" but other than that I don't see a problem.

You do appear to be declaring one on line 23 as well, or was that supposed to be an accessor?

If is were my implementation the private member would be ProcessedPayroll* pNext; and the accessor would be ProcessedPayroll * getNext() and the mutator void setNext(ProcessedPayroll * next) For the rest of the linked list, you need to have a "head" pointer that either points to NULL if the list is empty, or the first object in the list. The last object on the list will have its "next" pointer point to NULL.

How things are added to the linked list depends on the importance of ordering to the list. For a standard linked list, it is easiest to add elements at the head, but then when the data is accessed in the normal fashion, the data is in the opposite order from how it was added. (The last added would be the first seen.)

If the elements are to be added to the end of the linked list to maintain the order, you must either iterate to the end of the list every time you want to add one, or maintain a pointer to the "tail" (last object in the list -- NULL if the list is empty).

I hope this was useful or that you've already solved it yourself :)

If you'd post the errors, or what the program is doing that it shouldn't (or isn't doing that it should). I'd have more of a clue as to what to do to help you.

If you're getting a compile error, the actual compiler message along with several lines on either side of the 'problem' would better allow me to help.

If its a run-time error, the actual error message as well as the associated source code would be necessary.

Keep us posted, good luck.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.