0

Hi,

I am for the first time using Strings in a program, and for some reason my program wont compile.

When I use integers the program compiles and runs fine, but since I've changed it to use strings it's giving the following error (Visual Studio):

error C2511: 'Leads::Leads(std::string)' : overloaded member function not found in 'Leads'

This error is reports to be on line 26 of the header file.


Header file:

using namespace std;
#include <string>
//--------------------------------------------------------
class Diary
{
public:
	Diary(string mainname) : m_Name(mainname){}

private:

protected:
	string m_Name;
};
//-------------------------------------------------------
class Leads : public Diary
{
public:
	Leads(string maindate, string mainname);

private:

protected:
	string m_MainDate;
};

Leads::Leads(string mainname) : m_Name(mainname)
{
	m_MainDate = maindate;
}

Main.cpp:

#include <iostream>
#include <string>
#include <vector>
#include "bellingsheets.h"

using namespace std;

int main ()
{
	vector<Diary>vectorname;

	do{
		int choice = 0;
		cout << "Choose one of the options below:" << endl;
		cout << "1) Enter a lead" << endl;
		cout << "2) Exit the program" << endl;
		cin >> choice;
		cin.ignore();

		switch(choice)
		{
		case 1:
			{
				cout << "You chose to enter a lead" << endl;
				//---------------------
				//Collect the leads details
				//---------------------
				string mainname;
				cout << "Name? " << endl;
				getline (cin, mainname);

				string maindate;
				cout << "Date ? DDMMYY " << endl;
				getline (cin, maindate)

				//create a pointer to the base class ' Diary ' objects
				Diary *ptrToDiary;

				//create an object of type Diary called ' node '
				Diary node(mainname, maindate);


				//the pointer 'ptrToDiary' is assingned the address of the object 'node'
				ptrToDiary = &node;

				//put the pointer into the list
				vectorname.push_back( *ptrToDiary );
				cout << "past push Lead to list" << endl;

				break;
			}

		case 2:
			{
				cout << "You chose to exit the program" << endl;
				break;
			}
		}
	}
	while(true);

	system ("PAUSE");

	return 0;
}

I really am confused about this.

Is it because I haven't initialized the strings in the constructor?

When I was using integers in the constructor the program works fine, for example:

//constructor
Leads(int name = 0, int date = 0);

Hope someone can point out my error.

Many thanks!

Carrots

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by Ancient Dragon
0

line 18 has two parameters, line 26 only has one.

Never put the function implementation code into a header file because the linker will report duplicate declaration errors.

This topic has been dead for over six months. 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.