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 6930295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:25:44+00:00 2026-05-27T11:25:44+00:00

I am writing c++ program. This is snippet of main method: Student * array

  • 0

I am writing c++ program.

This is snippet of main method:

 Student * array = new Student[4];

    int i = 0;

    for(char x = 'a'; x < 'e'; x++){        

       array[i] = new Student(x+" Bill Gates");
        i++;
    }
    defaultObject.addition(array, 4);

This line array[i] = new Student(x+" Bill Gates"); throws an error:

g++    -c -g -MMD -MP -MF build/Debug/Cygwin-Windows/Run.o.d -o build/Debug/Cygwin-Windows/Run.o Run.cpp
In file included from Run.cpp:12:
Assessment3.hpp:53:39: warning: no newline at end of file
Run.cpp: In function `int main(int, char**)':
Run.cpp:68: error: no match for 'operator=' in '*((+(((unsigned int)i) * 8u)) + array) = (string(((+((unsigned int)x)) + ((const char*)" Bill Gates")), ((const std::allocator<char>&)((const std::allocator<char>*)(&allocator<char>())))), (((Student*)operator new(8u)), (<anonymous>->Student::Student(<anonymous>), <anonymous>)))'
Student.hpp:19: note: candidates are: Student& Student::operator=(Student&)
make[2]: Leaving directory `/cygdrive/g/Aristotelis/C++/assessment3'
make[1]: Leaving directory `/cygdrive/g/Aristotelis/C++/assessment3'
make[2]: *** [build/Debug/Cygwin-Windows/Run.o] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2

BUILD FAILED (exit value 2, total time: 3s)

Student class is over here:

#include "Student.hpp"
#include <string>
using namespace std;

Student::Student(){
    in = "hooray";
}

Student::Student(string in) {
    this -> in = in;
}

Student::Student(const Student& orig) {
}

Student::~Student() {
}
Student & Student::operator=(Student & student){
    if(this != &student){
        this->in = student.in;
    }
    return *this;
}

Header file is here:

#include <string>
using namespace std;

#ifndef STUDENT_HPP
#define STUDENT_HPP

class Student {
public:
    Student();
    Student(string in);
    Student(const Student& orig);
    virtual ~Student();
    Student & operator=(Student & student); // overloads = operator
private:
    string in;
};

#endif  /* STUDENT_HPP */

This part of program creates array of type Student and stores objects of type student. The the array is passed to compare the values according to bubble sort. What might be the problem?

  • 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-05-27T11:25:45+00:00Added an answer on May 27, 2026 at 11:25 am

    ‘array’ is an array of students declared on the freestore not of array of pointers to students so you can’t assign a pointer to them, new returns a pointer to a new location on the freestore. Instead you assign a student to the indexed location.

    //no new, you are assigning to a memory block already on the 
    array[i]=student("bob");
    

    Also whilst I am here, you can’t concatenate a C string and a char like that. You can however use a std::string to do that heavy lifting.

    char x='a';
    std::string bill("bill gates");
    std::string temp=bill+x;
    

    Finally, you will save a lot of time, if you a vector instead a C array, a vector will manage it’s own memory and provides a interface for you to use.

    std::vector<student> array(4, student("Bill Gates"));
    

    Vectors and string are the defacto way of dealing with arrays and string in c++.

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

Sidebar

Related Questions

I am writing c++ program. This is Student class: #include Student.hpp #include Home.hpp #include
I am writing this java program to find all the prime numbers up to
Writing a python program, and I came up with this error while using the
I'm actually writing an MPI program. This is a basic client / server pattern.
I've run into this while writing a Traveling Salesman program. For an inner loop,
I'm writing this program that will need to access the registry to pull some
I'm writing a program using python 2.6 and pyqt4. I want this program to
Hi there I am writing this program but I can't get it to even
Alright, so I'm writing this program that essentially batch runs other java programs for
I'm writing a program in C++ using WINAPI to monitor certain directory for new

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.