I'm getting a "IntelliSense no default constructor exists for class "Person" line 71." Also am getting error c2512: 'Person:' no appropriate default constructor available...
There is a constructor there which confuses me on why I'm getting an error?

#include <iostream>
#include <string>
using namespace std;

class Bio
{
public:
	Bio();
	Bio(string name, string street, string city, string state, string postalcode);
	void print() const;
private:
	string name, street, city, state, postalcode;
};

Bio::Bio(){name = street = city = state = postalcode = "";}
Bio::Bio(string aName, string aStreet, string aState, string aCity, string aPostalCode)
{ name = aName, street = aStreet; state = aState; city = aCity; postalcode = aPostalCode; }

void Bio::print() const
{
	cout << name << " : " << street << " : " << state << " : " << city << " : " << postalcode << endl;
}

class Person
{
public:
	Person(Bio &); // constructor
	void getBio(Bio &) const;
	void setBio(Bio &);
	virtual void print() const; //print derived classes
	virtual string getTitle() const = 0;

private:
	Bio bio;
};


Person::Person(Bio &z)
{
	bio = z;
}

void Person::getBio(Bio &a) const
{
	a = bio;
}

void Person::setBio(Bio &a)
{
	bio = a;
}

void Person::print() const
{
	bio.print();
}

class Student : public Person 
{
public:
	Student (Bio &bio, float gpa);
	void print() const;
	float getGPA() const;
	void setGPA (float);
	string getTitle() const;
private:
	float gpa;
};

Student::Student(Bio &bio, float gpa)
{
	bio = bio;
	gpa = gpa;
}

void Student::print() const
{
	cout << "Student starts out : Student bio for";
}

float Student::getGPA() const
{
	return gpa;
}

void Student::setGPA(float aGPA)
{
	gpa = aGPA;
}

string Student::getTitle() const
{
}



int main()
{
	cout <<"Creating Bio object for John Smith" << endl;

	Bio j ("John Smith", "123 Main St.", "Chicago", "IL", "12345");
	j.print();

	cout <<"Changed bio for prof object." << endl;

	Bio n("Nana Liu", " 3000 N. Campbell Ave", "Chicago", "IL", "60618");
	n.print();

	//Person john(j);
	return 0;
}

A default constructor is one you can call without any arguments, either because it actually takes no arguments, or all of the parameters are defaulted. Your Person class has a constructor, but it has one non-default parameter.

Why does it need one then? Why is it asking for one, especially because I'm referencing Bio in Person's parameters...

Edited 5 Years Ago by DaniwebOS: n/a

I'm failing to see the point of lines 72 and 73. Perhaps there should be a "this" in there somewhere? That would solve line 73's problem, but not line 72. I'm looking in vain on line 67 for a variable called "bio".

Edited 5 Years Ago by VernonDozier: n/a

I'm failing to see the point of lines 72 and 73. Perhaps there should be a "this" in there somewhere? That would solve line 73's problem, but not line 72. I'm looking in vain on line 67 for a variable called "bio".

I can see this-> being used but it wouldnt be able to access bio has its set privately... the only other idea I have is to use getBio

well i assigned line 72 using "this->getBio(bio);" which seemed to work but like you said it wouldn't solve line 73.

Edited 5 Years Ago by DaniwebOS: n/a

Why does it need one then? Why is it asking for one, especially because I'm referencing Bio in Person's parameters...

Student derives from Person and doesn't call the Person constructor in any of its own constructors. Thus the compiler assumes you want the default constructor to be used, which doesn't exist. End result: compiler error.

Student derives from Person and doesn't call the Person constructor in any of its own constructors. Thus the compiler assumes you want the default constructor to be used, which doesn't exist. End result: compiler error.

Your not referring to a initializer list, right? Can you give me an example of how to do this? I'm confused at this point...

Well I fixed the problem by adding Person(); yet I doubt I even did this properly to the point where it will function properly with the program.

Edited 5 Years Ago by DaniwebOS: n/a

This article has been dead for over six months. Start a new discussion instead.