I am just learning C++, and am having a hard time with creating a class definition. Can you please help me understand what I am doing wrong in the following code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
// Student.h
#pragma once
ref class Student
{
private:
int id;
double gpa;
int credits;
Student() {};
public:
Student(int, double, int);
void setGPA(double);
void setCredits(int);
int getID() {return id;}
double getGPA() {return gpa;}
int getCredits() {return credits;}
};
i dont know why ur compiler return that error..when i compile ur program the error is different..
student.h(3) : error C2143: syntax error : missing ';' before '<class-head>'
student.h(3) : error C2501: 'ref' : missing storage-class or type specifiers
student.h(3) : fatal error C1004: unexpected end of file found
this is what i do to solve
#pragma once
class Student
{
private:
int id;
double gpa;
int credits;
Student() {};
EAStudent,
When I tried your code, I received the following error
myProgram\Student.h(4) : error C2814: 'myProgram::Form1::Student' : a native type cannot be nested within a managed type 'myProgram::Form1'
For the form, I have some basic controls added, but no logic on anything yet (except for adding #include "Student.h" to Form1.h) as I wanted to make sure that the class compiled properly first.
I dont' know if it makes a difference, but here is some additional information about my environment.
OS: Windows Vista
Software: Microsoft Visual C++ 2008
Microsoft .NET Framework version 3.5 SP1
I tried a different compiler and had similar errors to what EAStudent listed, and was able to get it to compile by removing the ref from before class Student in Student.h.
Now I am really confused as it seems my original logic was correct, and I am wondering if there is some issue with Microsoft Visual C++, or a setting that was incorrect.
Does anyone have any suggestions on what I could try?