No matching constructor for initialization error



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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65

//header file with constructor initialization within the StudentClub class
class StudentClub
{
public:
    StudentClub(Student* p, Student* v, Student* s, Student* t, vector<Student*> m);
};

//parametrized constructor 
StudentClub::StudentClub (Student* p, Student* v, Student* s, Student* t, vector<Student*> m)
{
    president = p;
    vicepresident = v;
    secretary = s;
    treasurer = t;
    member = m;
}

//main function 

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


using namespace std;

int main()
{
    string name;
    
    cout << "President: " << endl;
    cin >> name;
    Student p (name);
    
    cout << "Vice-President: " << endl;
    cin >> name;
    Student v (name);
    
    cout << "Secretary: " << endl;
    cin >> name;
    Student s (name);
    
    cout << "Treasurer: " << endl;
    cin >> name;
    Student t (name);
    
    //loop that keeps asking for names until a Q is typed
    vector <Student> clubmem;
    
    Student m (name);
    
    do
    {
        cout << "New Member (Q to quit): " << endl;
        cin >> name;
        clubmem.push_back(m);
    }
    while (m.get_name() != "Q");

    //ERROR ON THIS LINE OF CODE
    //No matching constructor for initialization of 'StudentClub'
    StudentClub club (&p, &v, &s, &t, &clubmem);


I include the header file and cpp file for StudentClub. My main function is giving me an error where it says that there is no matching constructor for the initialization of StudentClub. I'm not sure what the issue is any help would be greatly appreciated.

repeat.
You're trying to pass a pointer to your vector<Student>. This is a different than passing a vector<Student*> by value.
Last edited on
I this homework where you need to do things in a certain way ?
If not get rid of all this pointers.
Topic archived. No new replies allowed.