Hello, I looked around and saw similar problems, but None of the answers seemed to help my situation. Im almost done with my HW Just have come across this minor bump.

The error is in the title, and is happening in my addressEntry header, or cpp. not sure: : error C2512: 'addressEntry' : no appropriate default constructor available

its confusing me because I cant find any reason it won't compile. any help would be appreciated.

#include <iostream>
#include <cctype>
#include <string>
#include <fstream>

using namespace std;

#include "name.h"
#include "address.h"
#include "addressEntry.h"
#include "addrbook.h"


void askUser(char & option);
void printMenu();
bool isValid(char option);
void optionOne();
void optionThree();

int main()
{
	Name myName("Andrew", "Russell");
	Name operatorName;
	Address operatorAddress;
	addressEntry operatoraddressEntry;
	char option = 0;
	char newOption = 0;
	char another = 'y';
	addrBook stuff;
	double itemToAdd;
	int counterToRemove = 0;
	string itemRemove;
	string newName,newLast,newAddress, newCity, newState, newZip, newPhone, newEmail, newBirthday, newPict;
	

	ofstream myfile ("address.dat");

	

	while(option != '5')
	{
		myName.printName();

		askUser(option);

			if(isValid(option))
				cout << "You selected: " << option << endl;
			else
				cout << "Invalid Entry selected\n";
		switch(option)
	{
	case '1':
				cout << "Enter your First Name: ";
					cin >> newName;
					operatorName.setFirstName(newName);
				cout << "Enter your Last Name: ";
					cin >> newLast;
					operatorName.setLastName(newLast);
				cout << "\nPlease Enter your Street Address: ";
					if(cin.peek() == '\n')
						cin.ignore();
					getline(cin, newAddress);
					operatorAddress.setStreet(newAddress);
				cout << "\nPlease Enter your City: ";
					cin >> newCity;
					operatorAddress.setCity(newCity);
				cout << "\nPlease Enter your State: ";
					cin >> newState;
					operatorAddress.setState(newState);
				cout << "\nPlease Enter your Zip Code: ";
					cin >> newZip;
					operatorAddress.setZip(newZip);
				cout << "\nPlease Enter your Phone Number: ";
					if(cin.peek() == '\n')
						cin.ignore();
					getline(cin, newPhone);
					operatoraddressEntry.setPhoneNumber(newPhone);
				cout << "\nPlease Entr your Birthday: ";
					if(cin.peek() == '\n')
						cin.ignore();
					getline(cin, newBirthday);
					operatoraddressEntry.setBirth(newBirthday);
				cout << "\nPlease Enter your Email Address: ";
					cin >> newEmail;
					operatoraddressEntry.setEmail(newEmail);
				cout << "\nPlease Enter your Pict File: ";
					cin >> newPict;
					operatoraddressEntry.setPict(newPict);
					
					stuff.add(operatorName.getFullName() + operatorAddress.getFullAddress() + operatoraddressEntry.getFullInfo());
		break;
	case '2':
		stuff.printUsed();
		break;
	case '3':
		stuff.print();
		break;
	case '4':
		// prompt for counting
		// number to remove
		stuff.remove(counterToRemove-1);
		break;
	case '5':
		cout << "Goodbye!\n";
		break;
	default:
		cout << "Error";
		

		}
		
	}

	 myfile.close();

		
	return 0;
}


void askUser(char & option)
{
	printMenu();
	cin >> option;
}
void printMenu()
{
	cout << "1. Add a new addressEntry to the AddressBook\n";
	cout << "2. Find out how many items in the AddressBook\n";
	cout << "3. Print out all the items in the AddressBook\n";
	cout << "4. Delete an item from the AddressBook\n";
	cout << "5. Exit the Program\n\n";
}


bool isValid(char option)
{
	if(option > 53 || option < 49) 
		return false;
	else
		return(true);
}

void optionOne()
{
	string newName,newLast,newAddress, newCity, newState, newZip, newPhone, newEmail, newBirthday;
	Name operatorName;
	Address operatorAddress;
	
	addrBook stuff;
			
				cout << "Enter your First Name: ";
					cin >> newName;
					operatorName.setFirstName(newName);
				cout << "Enter your Last Name: ";
					cin >> newLast;
					operatorName.setLastName(newLast);
				cout << "\nPlease Enter your Street Address: ";
					if(cin.peek() == '\n')
						cin.ignore();
					getline(cin, newAddress);
					operatorAddress.setStreet(newAddress);
				cout << "\nPlease Enter your City: ";
					cin >> newCity;
					operatorAddress.setCity(newCity);
				cout << "\nPlease Enter your State: ";
					cin >> newState;
					operatorAddress.setState(newState);
				cout << "\nPlease Enter your Zip Code: ";
					cin >> newZip;
					operatorAddress.setZip(newZip);
			
					
				
				
				// End of, Input
		   
		   cout << "\n****This is the Information that you Have provided****" << endl << endl;
		   cout << "Name & Address:\n" << newName << " " << newLast << endl;
		   cout <<  newAddress << "\n" << newCity << ", " << newState << " " << newZip << endl;
		   cout << "Phone Number: " << newPhone << endl;
		   cout << "Birth Date: " << newBirthday << endl;
		   cout << "Email: " << newEmail << endl;
		 
			    
	

}


void optionThree()
{ 
  string line;
  ifstream myfile ("address.dat");
  cout << "\n\n";
  if (myfile.is_open())
  {
    while (! myfile.eof() )
    {
      getline (myfile,line);
      cout << line << endl;
    }
    myfile.close();
  }

  else cout << "Unable to open file"; 
}

Here is the Header and The cpp that are causing the problem.

#ifndef ADDRESSENTRY_H
#define ADDRESSENTRY_H

#include <string>

class addressEntry
{
public: 
	addressEntry::addressEntry(string phoneIn, string birthIn, string emailIn, string pictIn);
	string addressEntry::getPhoneNumber() const;
	string addressEntry::getBirthday() const;
	string addressEntry::getEmail() const;
	string addressEntry::getPict() const;
	string addressEntry::getFullInfo() const;

	void addressEntry::setPhoneNumber(string phoneIn);
	void addressEntry::setBirth(string birthIn);
	void addressEntry::setEmail(string emailIn);
	void addressEntry::setPict(string pictIn);
	


private:
 string phone;
	string birth;
	string email;
	string pict;
};

#endif



#include <iostream>
#include <string>

using namespace std;

#include "addressEntry.h"

addressEntry::addressEntry(string phoneIn, string birthIn, string emailIn, string pictIn)
{
			phone = phoneIn;
			birth = birthIn;
			email = emailIn;
			pict = pictIn;
}
	
	string addressEntry::getPhoneNumber() const
	{
		return(phone);
	}
	string addressEntry::getBirthday() const
	{
		return(birth);
	}
	string addressEntry::getEmail() const
	{
		return(email);
	}

	string addressEntry::getPict() const
	{
		return(pict);
	}

	string addressEntry::getFullInfo() const 
	{
		return("Phone Number:" + phone + "\n" + email + "\n" + birth + "\n" + pict + "\n");
	}


	void addressEntry::setPhoneNumber(string phoneIn)
	{
		phone = phoneIn;
	}
	void addressEntry::setBirth(string birthIn)
	{
		birth = birthIn;
	}
	void addressEntry::setEmail(string emailIn)
	{
		email = emailIn;
	}
	void addressEntry::setPict(string pictIn)
	{
		pict = pictIn;
	}

1. Use code tag properly:
[code=c++] source(s)

[/code]
It's too hard to answer you without line numbers in formatted (by code tag) source.

2. It's a very typical error. You define a constructor of the class addressEntry:

addressEntry::addressEntry(
    string phoneIn, 
    string birthIn,
    string emailIn,
    string pictIn);

Therefore you must explicitly define all constructors needed for this class using. You forgot this C++ rule ;)...

Look at this declaration from the main function:

addressEntry operatoraddressEntry;

Obviously, a default constructor needed (constructor without parameters). No such constructor in your class. Define it - that's all.

3. Try to avoid class name style like addressEntry. Common practice is AddressEntry (see Name and Address in your code).

Member Avatar for r.stiltskin

The error message is telling you exactly what the problem is. In your main function you are declaring an addressEntry object addressEntry operatoraddressEntry; without supplying any arguments. In order to do that, your addressEntry class must have a default constructor, meaning a constructor that takes no arguments: addressEntry(); But the only constructor in your addressEntry class is this one addressEntry(string phoneIn, string birthIn, string emailIn, string pictIn); which takes 4 arguments.

Just add a default constructor to the class header and implementation files.

By the way, in your header file the "addressEntry::" part of each line is unnecessary. You only need that in the implementation file.

Look,
Here's the key:
If you do dont provide any constructor to the Class, the compiler generates, automatically, a defalt no-argument constructor.
But, if define even one constructor yourself, the compiler won't generate any constructor for you.
Saying this, I mean that if you defined a 2 argument constructor and no other constructor is defined, you cannot create object without specifying those two arguments. You have two options, either define a dummy no-argument constructor, or use the default arguments in your 2-argument constructor.

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.