Class Error

Can somebody please explain why I get this error: [Error] no matching function for call to 'Quizdata::Quizdata()'
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <iostream>
#include <string>
using namespace std;

class Quizdata
{
   private:
   	string studentNAME;
   
   public:
      Quizdata (string);       
};

Quizdata::Quizdata(string nam)        
{  
   studentNAME = nam;
}



int main()
{
   Quizdata student1;    

	string n;


   	cout << "What is the students name" << endl;
    cin.get();
    getline(cin, n);
    student1.Quizdata(n);

    
   return 0;
}
On line 23, you are trying to default construct a Quizdata object, but the only constructor you have defined is one that takes a string (line 11).

You can't re-call the constructor for student1 on line 31 anyway; just move line 23 down to that spot and pass the string in when constructing student1.
Quizdata student1(n);
Topic archived. No new replies allowed.