By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,972 Members | 883 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,972 IT Pros & Developers. It's quick & easy.

Needing some help on Classes and Constructors and proper definitions

P: 2
This is what I have so far, I still need some help.

Student.h file:
Expand|Select|Wrap|Line Numbers
  1. #ifndef STUDENT_H
  2. #define STUDENT_H
  3.  
  4. #include <iostream>
  5. #include <string>
  6. #include <cstdlib>
  7.  
  8. struct Name {
  9.   std::string firstName;
  10.   std::string lastName;
  11. };
  12.  
  13. enum Year {
  14.     FRESHMAN = 1,
  15.     SOPHMORE,
  16.     JUNIOR,
  17.     SENIOR,
  18. };
  19.  
  20. class Student
  21. {
  22. private:
  23.         Name name;
  24.         int idNumber;
  25.         std::string department;
  26.         Year year;
  27. public:
  28.         Student(const std::string& student, int id_number, const std::string& department, Years);
  29.         Student(const std::string& student, int id_number);
  30.         Student();
  31.  
  32.         int getidNumber();
  33.         std::string getName();
  34.         std::string getdepartment();
  35.         Year getYear();
  36.  
  37.         void setName(const Name& student_name);
  38.         void setidNumber(int id_number);
  39.         void setdepartment(const std::string student_department);
  40.         void setyear(Year students_current_year);
  41. };
  42.  
  43. #endif
Here is the error that Student.cpp is giving me:
Expand|Select|Wrap|Line Numbers
  1. Student.cpp:8:1: error: 'Student' does not name a type
  2.  Student::Student(const std::string& student, int id_number, const std::string& department, Year year)
  3.  ^~~~~~~
  4. Student.cpp:16:1: error: 'Student' does not name a type
  5.  Student::Student(const std::string& student, int id_number)
  6.  ^~~~~~~
  7.  
Student.cpp file:
Expand|Select|Wrap|Line Numbers
  1. #ifndef STUDENT_H
  2. #define STUDENT_H
  3.  
  4. #include <string>
  5. #include <cstdlib>
  6. #include "Student.h"
  7.  
  8. Student::Student(const std::string& student, int id_number, const std::string& department, Year year)
  9. {
  10.   Name name = setName();
  11.   idNumber = setidnumber();
  12.   department = setdepartment();
  13.   Year year = setyear();
  14. };
  15.  
  16. Student::Student(const std::string& student, int id_number)
  17. {
  18.   Name name = std::student;
  19.   idNumber = std::id_number;
  20. };
  21.  
  22. #endif
hw3.cpp file:
Expand|Select|Wrap|Line Numbers
  1. #ifndef STUDENT_H
  2. #define STUDENT_H
  3.  
  4. #include <iostream>
  5. #include <string>
  6. #include <cstdlib>
  7. #include "Student.h"
  8. #include "Student.cpp"
  9.  
  10. using namespace std;
  11.  
  12. int main()
  13. {
  14.   Student::student()
  15.  
  16.   void displayStudent(Student);
  17.  
  18.   return 0;
  19. }
  20.  
  21. #endif
Let me know where I'm making mistakes/lead/help me towards the right direction. Thanks so much!
Jul 6 '17 #1
Share this Question
Share on Google+
3 Replies


weaknessforcats
Expert Mod 5K+
P: 9,197
This code in class Student won't compile and that would be enough for the compiler to say Student is not a type.

Expand|Select|Wrap|Line Numbers
  1. public:
  2.         Student(const std::string& student, int id_number, const std::string& department, Years);
  3.  

Look closely at the last argument of the constructor. All it says is Years. It needs a type. Like enum Year:

Try this:

Expand|Select|Wrap|Line Numbers
  1. public:
  2.         Student(const std::string& student, int id_number, const std::string& department, enum Year Years);
  3.  
  4.  
  5.  
  6.  
Post again if you are still stuck.
Jul 7 '17 #2

P: 2
It's still throwing off numerous errors even with enum defined.
Jul 7 '17 #3

weaknessforcats
Expert Mod 5K+
P: 9,197
The number of errors is not important. Error 1 can cause Error 2,3,4,5,6, etc...

What you have to do is fix the first error only. Then recompile. If there are still errors, fix only the first one and recompile. You will eventually get them all.
Jul 7 '17 #4

Post your reply

Sign in to post your reply or Sign up for a free account.