Hi all, I know this is a trivial question but I really got stuck. I keep getting "non-1value in assignment" when trying to access the pointer variable "next" using the getNext() function. It didn't show any error if I change the last 2 lines to

temp_ptr->next = after->next; //when "DivisionNode* next" is set to public, no error
after->next = temp_ptr;

The problem arises when I try using getNext(), as shown in the code below(located in the last 2 lines).
This is my school assignments and I'm not allowed to set the pointer "next" to public.. kindly need your help as I've already stuck in this for so long.

class DivisionNode {

 public:
    DivisionNode();
    DivisionNode(int divNum);
    ~DivisionNode();

    int getDivisionNum();
    DivisionNode* getNext();

    void setDivisionNum(int divNum);

    void setNext(DivisionNode* n);

private:
    int divisionNum;
    DivisionNode* next;
};

typedef DivisionNode* DivisionNode_Ptr;


#include "DivisionNode.h"
#include <iostream>

DivisionNode::DivisionNode():divisionNum(0),next(NULL){


}

DivisionNode::DivisionNode(int divNum):divisionNum(divNum) {


}

DivisionNode::~DivisionNode(){


}

int DivisionNode::getDivisionNum(){

 return divisionNum;
}

DivisionNode* DivisionNode::getNext(){

 return next;
}

void DivisionNode::setDivisionNum(int divNum){

divisionNum = divNum;


}

void DivisionNode::setNext(DivisionNode* n){

    next = n;

}

//Want a new node to be inserted after the node pointed by "after"
void DivisionNode_insert(DivisionNode_Ptr after, int the_number)
{
DivisionNode_Ptr temp_ptr;

temp_ptr = new DivisionNode(the_number);

temp_ptr->getNext() = after->getNext(); //error goes here
after->getNext() = temp_ptr;            //error goes here


}

Pass your after pointer to your temp_ptr's setNext method, something like temp_ptr->setNext(after->getNext());

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.