3 Replies - 305 Views - Last Post: 25 March 2013 - 10:31 AM Rate Topic: -----

#1 nephtyhephty  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 33
  • Joined: 25-September 12

ERROR: 'Student::NumCourses' : is not a type name

Posted 25 March 2013 - 12:52 AM

I get 2 errors and I don't know why I can't make int courses(NumCourses);
I get these errors:
'Student::NumCourses' : is not a type name
'NumCourses' : undeclared identifier

#include <iostream>
#include <string>

using namespace std;

class Student
{
public:
	int NumCourses;

	Student(string studentname, int studentcourses)
	{
		name = studentname;
		NumCourses = studentcourses;
	}


	string name;
	int courses[NumCourses];
	double cGPA, dGPA, pGPA;

};


Is This A Good Question/Topic? 0
  • +

Replies To: ERROR: 'Student::NumCourses' : is not a type name

#2 jimblumberg  Icon User is offline

  • member icon


Reputation: 4005
  • View blog
  • Posts: 12,361
  • Joined: 25-December 09

Re: ERROR: 'Student::NumCourses' : is not a type name

Posted 25 March 2013 - 03:17 AM

In C++ array sizes must be a compile time constant.

Jim
Was This Post Helpful? 0
  • +
  • -

#3 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1327
  • View blog
  • Posts: 4,554
  • Joined: 19-February 09

Re: ERROR: 'Student::NumCourses' : is not a type name

Posted 25 March 2013 - 10:17 AM

You could use a vector or a dynamic array.
Was This Post Helpful? 0
  • +
  • -

#4 nephtyhephty  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 33
  • Joined: 25-September 12

Re: ERROR: 'Student::NumCourses' : is not a type name

Posted 25 March 2013 - 10:31 AM

Alright, thanks for the help guys. Just got it working.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1