0

I am attempting to make a class called Profile and have numerous profiles in an array (70 to be exact).

//profile.h

Class Profile {
  int _age;
  string _fname;
  string _lname;
  int _height;
  char _gender;

  Profile(int val, char gender) : _age(val), _gender(gender) {  }

  int getHeight();

  int getAge();
};
//profile.cpp

int Profile::getHeight() {
    return _height;
     }

int Profile::getAge() {
     return _age;
     }
//main.cpp

#include "Profile.h"

int main() {

Profile myarray[70];
return 0;

}

The error is that in Profile.h, no matching function to call Profile:: Profile()

Edited by Blitze: n/a

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by Blitze
0

C++ attempts to call the default constructor for each element of an array. Profile doesn't have a default constructor (only one that takes two arguments). Either provide that default constructor or make myarray hold pointers to Profile instances.

C++ will provide a default constructor for a class only if you don't provide one of your own.

Edited by griswolf: mention why

0

Ok, i have made it use pointers and it works beautifully. I have a file with all of the profiles filled out and I thought that would allow it to call it for the array obviously it did not.

Thank you very much for your time!
~Blitze

Edited by Blitze: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.