Note that there are some explanatory texts on larger screens.

plurals
  1. POTrouble with Array in C++ header
    primarykey
    data
    text
    <p>So I'm trying to make a simple little database in C++ for fun. I want to do it using arrays. But I keep getting errors though. I want it to increment integer 'i' after the user enters in the student information. So that way it will allow a Infinite amount of names ages to be entered. And I want to eventually store the names the user enters into a notepad. I could do this in a int main(), but I am trying to experiment with headers. </p> <p>I am having a lot of trouble with the arrays.</p> <p>Heres a snippet of code that I am using in the header and the CPP file. I tried declaring int 'i' in private and int 'b' in public and putting them into the arrays and then pointing the private to the public in the CPP file but it didn't work. If you guys could help me that would be great thanks! BTW I'm new so please forgive my ignorance. I'm not whether I used the pointers right either.</p> <pre><code> #include &lt;string&gt; class student3 { protected: int i; std :: string *_studentFirstName[]; std :: string *_studentLastName[]; int *_studentAge[]; double *_studentGPA[]; public: int b; void setstudentFirstName(std :: string firstName[]); void setstudentLastName(std :: string lastName[]); void setstudentAge(int Age[]); void setstudentGPA(double GPA[]); std :: string getstudentFirstName(); std :: string getstudentLastName(); int getstudentAge(); double getstudentGPA(); } </code></pre> <hr> <pre><code>#include "student3.h" void student3 :: setstudentFirstName(std :: string firstName[b]) { *_studentFirstName[i] = firstName[b]; } void student3 :: setstudentLastName(std :: string lastName[b]) { *_studentLastName[i] = lastName[b]; } void student3 :: setstudentAge(int Age[b]) { *_studentAge[i] = Age[b]; } void student3 :: setstudentGPA(double GPA[b]) { *_studentGPA[i] = GPA[b]; } std :: string student3 :: getstudentFirstName() { return *_studentFirstName[i]; } std :: string student3 :: getstudentLastName() { return *_studentLastName[i]; } int student3 :: getstudentAge() { return *_studentAge[i]; } double student3 :: getstudentGPA() { return *_studentGPA[i]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload