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()

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.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.