Can someone tell me why I get non-object errors if I don't instantiate the objects with 3 strings? I provided default arguments for this object, so what is the problem? Sample error received when objects not instantiated (receive them for all functions):
c:\Documents and Settings\Owner.Mynotebook\My Documents\Visual Studio Projects\helloWorld\helloWorld.cpp(52): error C2228: left of '.inputVals' must have class/struct/union type
Thanks, and Happy Easter!
Code:
#include <iostream>
#include <string>
using namespace std;
class TelBook
{
protected:
string last_;
string first_;
string tel_;
public:
TelBook(string, string, string);
void inputVals();
void dispVals();
void assignVals(TelBook*);
};
TelBook::TelBook(string f = "", string l = "", string t = "")
{
first_ = f;
last_ = l;
tel_ = t;
}
void TelBook::inputVals()
{
cout << "Enter the last name: ";
getline(cin, last_, '\n');
cout << "\nEnter the first name: ";
getline(cin, first_, '\n');
cout << "\nNow enter the telephone number: ";
getline(cin, first_, '\n');
}
void TelBook::dispVals()
{
cout << "Last name: " << last_ << ", first name: " << first_
<< ", telephone number: " << tel_ << endl;
}
void TelBook::assignVals(TelBook *myTelEntry)
{
myTelEntry->last_ = last_;
myTelEntry->first_ = first_;
myTelEntry->tel_ = tel_;
}
int main()
{
TelBook myTelBookObject();
myTelBookObject.inputVals();
myTelBookObject.dispVals();
TelBook mySecondTelBookObject();
mySecondTelBookObject.inputVals();
mySecondTelBookObject.assignVals(&myTelBookObject);
myTelBookObject.dispVals();
return 0;
}