no instance of constructor "Persona::Persona " matches the argument list

I get this error and i do not know how to fix it:
no instance of constructor "Persona::Persona " matches the argument list

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
  // Añadir personas al archivo
void addNewPersona(vector<Persona *> &personas) {
	int Id;
	cout << "Asigne un ID para la persona: ";
	cin >> Id;

	// Verifica si el ID existe.
	int exists = -1;
	for (size_t i = 0; i < personas.size(); i++) {
		if (personas[i]->getId() == Id) {
			exists = i;
			break;
		}
	}


	//Actualiza datos de personas nuevas
	if (exists != -1) {
		cout << "Este ID ya es existente." << endl;
	}

	else {
		// Añade la persona con todos sus datos
		string nombrecompleto;
		int edadpersona, drecibida;
		cout << "Entrar nombre con apellidos: ";
		cin >> nombrecompleto;
		cout << "Entrar edad: ";
		cin >> edadpersona;
		cout << "Entrar dosis recibidas: ";
		cin >> drecibida;
		Persona *persona = new Persona(nombrecompleto, edadpersona, drecibida);

		//Persona *persona = new Persona(nombrecompleto, edadpersona, drecibida);
		personas.push_back(persona);
		cout << "Persona añadida exitosamente." << endl;
	}

	cout << endl;
Never mind i forget Id int when creating Persona. Thanks
error C2059: syntax error: '}'
error C2143: syntax error: missing ';' before '}'
error C2143: syntax error: missing ';' before '{'
error C2447: '{': missing function header (old-style formal list?)

in this part:
void addNewPersona(vector<Persona *> &personas) {
int id;
cout << "Asigne un ID para la persona: ";
cin >> id;

int exists = -1;
Full error messages also have line numbers.
The issue could be bad syntax before the function you posted.

Make sure you have 1 { for every }.
Last edited on
Note: Lines 8-18 could use C++ Standard Library
http://www.cplusplus.com/reference/algorithm/find_if/
1
2
3
4
5
auto it = std::find_if( personas.begin(), personas.end(),
  [Id](auto p){ return p->getId() == Id; } );
if ( it != personas.end() ) {
  cout << "Este ID ya es existente.\n";
}

Use of pre-made algorithms can simplify your code and thus avoid some errors.


PS. Why pointers/dynamically allocated objects?
Last edited on
Topic archived. No new replies allowed.