Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8959319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:24:29+00:00 2026-06-15T15:24:29+00:00

I have built a static stack of structures, and everything works – including creating

  • 0

I have built a static stack of structures, and everything works – including creating an array of the structures. However, for some reason I can’t set the top of the array to a structure.

In my .cpp file, in my push function, I keep erroring on the following line:

stackArray[top] = newStudent;

The error I am receiving is:

“51: no match for ‘operator=’ in ‘(((studentstack)this)->studentstack::stackArray + (+(((unsigned int)((studentstack*)this)->studentstack::top) * 24u))) = ((studentstack*)this)->studentstack::newStudent’ “

I am including my code below.

Header file:

#ifndef studentstack_H
#define studentstack_H

#include <iostream>
#include <string>

using namespace std;

class studentstack {
    private:
        int size;         // Stack size
        int top;          // Top of the Stack

        struct student {
            int ID;
            string Name;
            string Address;
            double GPA; 
        };
        student * stackArray;  // Pointer to the stack
        student * newStudent; // Pointer to the new student

    public: //Constructor
        studentstack(int);

        // Copy Constructor
        studentstack(const studentstack &);

        //Destructor
        ~studentstack();

        //Stack Operaations
        void push(string, int, double, string);
        void pop(int &);
        bool isFull() const;
        bool isEmpty() const;
    };

#endif

studentstack.cpp

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

using namespace std;

studentstack::studentstack(int SIZE) {
    stackArray = new student[SIZE];
    size = SIZE;
    top = -1;
    int ID = 0;
    double GPA = 0;
}

studentstack::studentstack(const studentstack &obj) {
    if (obj.size > 0)
        stackArray = new student[obj.size];
    else
        stackArray = NULL;

    size = obj.size;

    for (int count = 0; count < size; count++)
        stackArray[count] = obj.stackArray[count];

    top = obj.top;
}

studentstack::~studentstack() {
    delete [] stackArray;
}

void studentstack::push(string name, int id, double gpa, string address) {
    if (isFull()) {
        cout << "The stack is full.\n";
    } else {
        top++;
        newStudent = new student;
        newStudent-> Name = name;
        newStudent-> ID = id;
        newStudent-> Address = address;
        newStudent-> GPA = gpa;
        stackArray[top] = newStudent;
    }
}   

void studentstack::pop(int &id) {
    if (isEmpty()) {
        cout << "The stack is empty.\n";
    } else {
        id = stackArray[top].ID;
        top--;
    }
}

bool studentstack::isFull() const {
    bool status;

    if (top == size - 1)
        status = true;
    else
        status = false;

    return status;
}

bool studentstack::isEmpty() const {
    bool status;

    if (top == -1)
        status = true;
    else
        status = false;

    return status;
}

main.cpp

#include "studentstack.h"
#include <iostream>
#include <string>
using namespace std;

int main() {
    string name;
    int id, var;
    string address;
    double gpa;
    studentstack s[20];

    for(int x =0; x<20; x++) {
        cout << "New Student Name: " << endl;
        cin >> name;

        cout << "ID: " << endl;
        cin >> id;

        cout << "GPA: " << endl;
        cin >> gpa;

        cout << "Address: " << endl;
        cin >> address;

        s.push(name, id, gpa, address)
    }

    cout << "Popping: "
    for(int x = 0; x < 5; x++) {
        s.pop(var);
        cout <<var;
    }

    return(0);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T15:24:30+00:00Added an answer on June 15, 2026 at 3:24 pm

    You might want to cut down the example to a minimal piece of code showing the problem. What it comes down to is that you try to assign a student* to a an element in an array of student objects. A pointer to an object is different to an object:

    stackArray[0] = new student(); // does NOT work
    stackArray[0] = student();
    

    Note, that object are created in C++ by a constructor and not necessarily involving new. When you construct and object using new you still create an object but you also allocate space for it on the heap. By default, objects are created wherever they are defined. For example, student() creates an object on the stack which is then assigned to an object in the memory of stackArray[0].

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have built a static version of qt and download a static version of
I have built up an array of objects, created from a class, I wrote
I have built an app where the user can press a button and get
We have some solution that we built against a MOSS farm one of which
I have a static library that I have built with MinGW, I am trying
I have built a static library in my home directory and there is also
I have built a little static object for saving generic types to Isolated Storage
I have built a site which requires user to login. Now I have decided
I have built so far an application that allows the user to drag and
I have built a local DVD Database using Codeigniter, With film names etc in.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.