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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:47:01+00:00 2026-06-03T05:47:01+00:00

I encountered the following problem, and I don’t get any warnings or errors, just

  • 0

I encountered the following problem, and I don’t get any warnings or errors, just a program crash.

When I run in my menu printAll() after dummyData() initialisation. The moment I add one new student it just starts to loop the studentMenu().

Domain.h:

template <class T>
struct Array{
    int length;
    T * M;

    Array( int size ) : length(size), M(new T[size])
    {
    }
    ~Array()
    {
       delete[] M;
    }
};

template <class T>
struct Array{
    int length;
    T * M;

    Array( int size ) : length(size), M(new T[size])
    {
    }
    ~Array()
    {
       delete[] M;
    }
};

template <class T>
void addStudent(int a, int b, std::string c,Array <T> A){
    A.M[a].setStudent(a,b,c);
}

template <class T>
void DummyDataStudents(Array <T> A){
    for(int i=1; i<15; i++){
        A.M[i].setStudent(i, i,"student");
    }
    cout<<"Done Students"<<endl;
}

Controller.h

template <class T>
void _addStudent(Array <T> &A){
    int a,b;
    string c;
    cout<<"Enter ID:"<<endl;
    cin>>a;
    cout<<"Enter Group:"<<endl;
    cin>>b;
    cout<<"Enter Name:"<<endl;
    cin>>c;

    addStudent(a,b,c,A);
}

Student.cpp:

void Student::setStudent(int a,int b,string c){

this->ID = a;
this->group = b;
this->name = c;
}

Menu.cpp:

void Menu::mainMenu(Array <Student> &DBst,Array <Assignment> &DBas){
showMainMenu();
int ret = Menu::intInputHandler();

switch(ret){
case 1:studentMenu(DBst,DBas);break;
case 2:assignmentMenu(DBst,DBas);break;
case 3:statsMenu(DBst,DBas);break;
case 4:_printAll(DBst,DBas);break;
case 0:break;
default:cout<<"Wrong option selected!";break;
}
Menu::mainMenu(DBst,DBas);
}



void Menu::studentMenu(Array <Student> &DBst,Array <Assignment> &DBas){
    showStudentMenu();
    int ret = Menu::intInputHandler();

    switch(ret){
    case 1:_addStudent(DBst);break;
    case 2:break;
    case 3:break;
    case 4:break;
    case 5:_printAllStud(DBst);break;
    case 6:break;
    case 0:mainMenu(DBst,DBas);break;
    default:cout<<"Wrong option selected!";break;
    }
    Menu::studentMenu(DBst,DBas);
}

Main.cpp:

int main(){
//Main function of the program

    DummyDataStudents(DBst);

    DBst.M[10].setStudent(1,10,"sadasd");     //works just fine
    DBst.M[10].printStudent();cout<<endl;

    Menu main;      
    main.mainMenu(DBst,DBas);

    DBst.~Array();
    DBas.~Array();

    return 0;
}

///I think this should be enough to understand. When I add a new student I get loops of menu printing until it crashes; if I call printall() I get a crash directly. Please help and sorry for the long code.

  • 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-03T05:47:02+00:00Added an answer on June 3, 2026 at 5:47 am

    This is a problem:

    template <class T> void addStudent(int a, int b, std::string c,Array <T> A){
    

    the Array A is being passed by value, so it is being copied meaning there are now two instances of Array pointing to the same internal array M as there is no copy constructor defined for Array so a default copy constructor is generated. When addStudent() returns the internal array M is being deleted by the instance of Array local to the function. This leaves the remaining instance of Array A with a dangling pointer.

    Either implement a copy constructor and assignment operator (which I don’t think you want to do) or make Array non-copyable be declaring the copy constructor and assignment operator private.

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

Sidebar

Related Questions

I encountered following problem: I write program in c++ using VS2010. Debug build works
I've recently encountered the following problem with my application: it didn't show any console
I am in the process of changing my git-merge-workflow and encountered following problem: Up
I'm learning C# and I encountered the following problem. I have two classes: base
While making AutoHotkey-script I encountered the following problem. I need navigate listbox (one position
while designing my user control, i encountered the following problem: i would like to
I have the following problem that other people must have encountered. I am working
I encountered a problem dealing with UTF-8, XML and Perl. The following is the
I'm using new Facebook C# SDK 5.0.2, and I encountered the following problem: During
Following a C tutorial , I've encountered a type dependency that I don't know

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.