I have a "two stage" inheritance piece I'm writing. The overall class is telnumber, the worknumber is derived from telnumber, and billnumber is derived from worknumber. The problem is in in my billnumber.cpp. In the main there are two lines referring to the billnumber class with only 4 parameters, and one with 5 parameters. The one with 5 parameters compiles fine, but the two lines with 4 parameters give me the error message "No overloaded function takes 4 arguments. Below is my billnumber cpp. How do I add in a copy constructor for 4 arguments as well as 5?

#include "billnumber class.h"

billnumber::billnumber():
          worknumber("","","","")
{
}

billnumber::billnumber(string i_npa, string i_nxx, string i_line, string i_name, int i_numlines):
	worknumber(i_npa, i_nxx, i_line,i_name)
{
}
	
void billnumber::setnumlines(int& newnumlines)
{
	numlines=newnumlines;
}

int billnumber::getnumlines()
{
	return (numlines);
}
	
billnumber::~billnumber()
{
}

Here is the main:

ostream& operator << (ostream &out, telnumber &tn)
{
	tn.printtostream(out);
	return out;
}

int main()
{
	telnumber yournumber;
	telnumber paul("719","590","6768");
	telnumber bob("719","590", "6729");
	worknumber csstaff1 ("719","590","6732","Book Store");
	worknumber csstaff2 ("212","371","6940","Borland C++ Guru");
	worknumber csstaff3 ("405","612","3433","Visual C++ Expert");
	billnumber csdept ("719","590","6850","Dean of CS");
	billnumber library ("719","598","6708","Librarian");
	billnumber reception ("719","598","0200","Receptionist",35);
	cout << "Testing the overladen << operator with the virtual" << "printtostream()\n\n";
	cout << "The telephone numbers are: \n" << endl;
	cout << yournumber << endl;
	cout << paul << endl;
	cout << bob << endl;
	cout << "The working telephone numbers are: \n" << endl;
	cout << csstaff1 << endl;
	cout << csstaff2 << endl;
	cout << csstaff3 << endl;
	cout << "The billing telephone numbers are: \n" << endl;
	cout << csdept << endl;
	cout << library << endl;
	cout << reception << endl;
	cout << "Here endeth the hierarchy of the telephone!" << endl;

return 0;
}

I'm also getting three unresolved externals from the "print" function above main. It is declared as a virtual in the telnumber header and there is no implementation. I know I've been told about external errors before, but I can't seem to see where I've muffed this one thanks to the inheritance.

where is the 4 parameters constructor? What I can see is just a 5 parameters constructor and a default constructor.

where is the 4 parameters constructor? What I can see is just a 5 parameters constructor and a default constructor.

That's just it...I have tried to write the 4 parameter constructor, but I'm doing something wrong, it tells me I have a duplicate body or that I'm redefining among other things. I apparently don't know how to write it. My first attempt was to do it by just eliminating the fifth parameter and placing it above the constructor with 5 parameters...that was a no go. I then did the same, but took out the "worknumber" parameters and that didn't work either.

This is what I tried first:

billnumber::billnumber(string i_npa, string i_nxx, string i_line, string i_name):
	worknumber(i_npa, i_nxx, i_line,i_name)
{
}

// tried this second

billnumber::billnumber(string i_npa, string i_nxx, string i_line, string i_name):
{
}

Obviously neither works. What am I doing wrong? And can you tell me about the external errors above as well?

Al was either of those even close to what you were going to suggest?

Firstly, they are not copy constructot, just constructor.
Do you have declear a 4 parameters constructor in your head file?

I have no clue about the external issue

yes...the hierarchy works like this

telnum->worknum->billnum

There are three parameters in telnum declared and defined

Those three parameters are passed to worknum, which adds one (name)

Those 4 parameters are then passed to billnum, which adds a fifth (numlines).

At this point, all constructors work fine except that I need one in billnum which will hold the 4 parameters from telnum and worknum and all my attempts at that have failed miserably.

My other problem is with the ostream function right before main. It gives me three extern errors, one for each class, so I've defined something wrong somewhere for that also

Two simple examples, hopefully you'll get something figured out of those ...

class a
{
public:
    a(string s1, string s2){}
};
class b : public a
{
public:
    // default ctor
    b() : a("", "") {}

    // ctor with 4 strings
    b(string as1, string as2, string bs1, string bs2) : a(as1, as2) {}

    // ctor with 4 strings plus an int
    b(string as1, string as2, string bs1, string bs2, int bint) : a(as1, as2) {}
};
int main()
{
    b b1("asdf", "asdf", "asdf", "asdf");
    b b2("asdf", "asdf", "asdf", "asdf", 123);

    return 0;
}

The above changed so, that the 5 arg ctor has a default value for the integer argument, that way the 4 arg ctor can be dropped altogether ...

class a
{
public:
    a(string s1, string s2){}
};
class b : public a
{
public:
    // default ctor
    b() : a("", "") {}

    // ctor with 4 strings plus an int with default value zero
    b(string as1, string as2, string bs1, string bs2, int bint = 0) : a(as1, as2) {}
};
int main()
{
    b b1("asdf", "asdf", "asdf", "asdf");  // this one uses the default value
    b b2("asdf", "asdf", "asdf", "asdf", 123);

    return 0;
}
commented: very helpful without doing it for me +1

Thank you mitrim. Using your example, I was able to figure out the 4 vs 5 parameter problem.

If someone could look through the previous posts on this subject, I have this snippet as a virtual function in each of the classes

virtual void printtostream(ostream& out);

Since it is a virtual function it was not defined in any of the classes. My function, just slightly pre main is this

ostream& operator << (ostream &out, telnumber &tn)
{
	tn.printtostream(out);
	return out;
}

This gives me three external resolution errors. What am I forgetting to do?

nm, I'll post this separately..thanks again mitrim

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.