2014-02-17 6 views
0

Я новичок в C++ (я программист на C), поэтому прошу прощения, если это кажется глупым вопросом.Получение сообщения об ошибке в C++

Когда я запускаю эту программу, я получаю следующее сообщение об ошибке:

ошибка C2661: 'Student :: Студента: нет перегруженной функция принимает 2 аргумент

Я комментировал, где происходит ошибка (2 экземпляров) , Спасибо.

//Definition.cpp 

#include "Student.h" 

Student::Student(string initName, double initGPA) //error here and in main.cpp 
{ 
     name = initName; 
     GPA = initGPA; 
} 

string Student::getName() 
{ 
     return name; 
} 

double Student::getGPA() 
{ 
     return GPA; 
} 

void Student::printInfo() 
{ 
     cout << name << " is a student with GPA: " << GPA << endl; 
} 

//student.h 

#include <string> 
#include <iostream> 

using namespace std; 

class Student 
{ 
     private: 
       string name; 
       double GPA; 
     public: 
       string getName(); 
       double getGPA(); 
       void setGPA(double GPA); 
       void printInfo(); 
}; 


//main.cpp 

#include <iostream> 
#include "Student.h" 

int main() { 
     Student s("Lemuel", 3.2); //here is the error 

     cout << s.getName() << endl; 
     cout << s.getGPA() << endl; 

     cout << "Changing gpa..." << endl; 
     s.setGPA(3.6); 

     s.printInfo(); 
     return 0; 
} 
+0

Не отговаривать себя спросить сомнения. Просить сомнение является общим и не беспокоиться о его глупой ошибке или большой –

ответ

5

Ваш конструктор не объявлен.

Попробуйте это:

class Student 
{ 
     private: 
       string name; 
       double GPA; 
     public: 
       Student(string initName, double initGPA); 
       string getName(); 
       double getGPA(); 
       void setGPA(double GPA); 
       void printInfo(); 
}; 
Смежные вопросы