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 {

    DivisionNode(int divNum);

    int getDivisionNum();
    DivisionNode* getNext();

    void setDivisionNum(int divNum);

    void setNext(DivisionNode* n);

    int divisionNum;
    DivisionNode* next;

typedef DivisionNode* DivisionNode_Ptr;

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



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




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());

Edited 6 Years Ago by jonsca: n/a

This article has been dead for over six months. Start a new discussion instead.