I'm a fresh programmer.
So this is my first OOP program that I'm writing for a class. I'm getting a "double free or corruption (out)" error.
The program that I am writing basically makes Student objects and stores info about them like test scores(in an array), their name and ID. My teacher told us all the public and private member funtions so I started there. I wrote the basic structure and then through a bunch of cout statements to I could get it navigate through program properly. I'm slowly working it up and adding stuff little by little until I get it to do everything I need it to do.
I commented out all the class members that I haven't gotten to yet.
Have mercy on my sad sad code....
Code:
#include<iostream>
#include<string>
using namespace std;
class Student
{
private:
string name;
int id;
int * test;
int num;
// void makeArray()
// {
// cout << "making array...\n";
//
// }
public:
Student()
{
cout << "creating student...1\n";
setName("None");
setID(10);
}
Student(int n)
{
cout << "creating student...2\n";
setName("None");
setID(10);
}
Student(string nm, int i, int n)
{
cout << "creating student...3\n";
setName(nm);
setID(i);
}
void setName(string nm)
{
cout << "Setting name...\n";
cout << "The Name: ";
cin >> name;
}
void setID(int i)
{
cout << "setting ID...\n";
num = 3;
//makeArray();
}
// void setScore(int i, int s)
// {
//
// }
string getName() const
{
cout << name << endl;
}
int getID() const
{
cout << id << endl;
}
void showScore()
{
cout << "showing score";
}
void display()
{
cout << "showing display";
}
// ~Student()
// {
//
// }
};
int main()
{
cout << "In main\n";
Student studentA,
studentB(4),
studentC("Joe",40,5);
cout << "Before showing names...\n";
studentA.getName();
cout << "after studentA.\n";
studentB.getName();
cout << "after studentB.\n";
studentC.getName();
cout << "after studentC.\n";
return 0;
}
The error happens at this getName call in main: "studentA.getName();"
Where am I going wrong?