I'm getting an error in main() saying TitledEmployee is an undeclared identifier?

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

namespace Employees
{
    class Employee
    {
    public:
        Employee ( ) ;
        Employee ( string theName , string theSsn ) ;
        string getName ( ) const ;
        string getSsn ( ) const ;
        double getNetPay ( ) const ;
        void setName ( string newName ) ;
        void setSsn ( string newSsn ) ;
        void setNetPay ( double newNetPay ) ;
        void printCheck ( ) const ;
    private:
        string name ;
        string ssn ;
        double netPay ;
    } ;

    Employee::Employee ( ) : name ( "No name yet" ) , ssn ( "No number yet" ) , netPay ( 0 )
    { }

    Employee::Employee ( string theName , string theNumber ) : name ( theName ) , ssn ( theNumber ) , netPay ( 0 )
    { }

    string Employee::getName ( ) const
    {
        return name ;
    }

    string Employee::getSsn ( ) const
    {
        return ssn ;
    }

    double Employee::getNetPay ( ) const
    {
        return netPay ;
    }

    void Employee::setName ( string newName )
    {
        name = newName ;
    }
    void Employee::setSsn ( string newSsn )
    {
        ssn = newSsn ;
    }

    void Employee::setNetPay ( double newNetPay )
    {
        netPay = newNetPay ;
    }

    void Employee::printCheck ( ) const
    {
        cout << "\nERROR:  printcheck Function Called for an unidentified employee.\nAborting the program.\n" ;
        exit ( 1 ) ;
    }


    class SalariedEmployee : public Employee
    {
    public:
        SalariedEmployee ( ) ;
        SalariedEmployee ( string theName , string theSsn , double theWeeklySalary ) ;
        double getSalary ( ) const ;
        void setSalary ( double newSalary ) ;
        void printCheck ( ) ;
    private:
        double salary;
    } ;

    SalariedEmployee::SalariedEmployee ( ) : Employee ( ) , salary ( 0 )
    { }

    SalariedEmployee::SalariedEmployee ( string theName , string theNumber , double theWeeklyPay ) : Employee ( theName , theNumber ) , salary ( theWeeklyPay )
    { }

    double SalariedEmployee::getSalary ( ) const
    {
        return salary ;
    }

    void SalariedEmployee::setSalary ( double newSalary )
    {
        salary = newSalary ;
    }

    void SalariedEmployee::printCheck ( )
    {
        setNetPay ( salary ) ;
        cout << "\n____________________________\n" ;
        cout << "Pay to the order of " << getName ( ) << endl ;
        cout << "The sum of " << getNetPay ( ) << " Dollars\n" ;
        cout << "______________________________\n" ;
        cout << "Check Stub Non Negotiable \n" ;
        cout << "Employee Number:  " << getSsn ( ) << endl ;
        cout << "Salaried Employee.  Regular Pay:  " << salary << endl ;
        cout << "______________________________\n" ;
    }

    class TitledEmployee : public SalariedEmployee
    {
    public:
        TitledEmployee ( ) ;
        TitledEmployee ( string theName , string theTitle , string theSsn , double theSalary ) ;
        string getTitle ( ) const ;
        void setTitle ( string theTitle ) ;
        void setName ( string theName ) ;
    private:
        string title ;
    } ;

    TitledEmployee::TitledEmployee ( ) : SalariedEmployee ( ) , title ( "No title yet" )
    { }

    TitledEmployee::TitledEmployee ( string theName , string theTitle , string theSsn , double theSalary ) : SalariedEmployee ( theName , theSsn , theSalary ) , title ( theTitle )
    { }

    void TitledEmployee::setName ( string theName )
    {
        Employee::setName ( title + theName ) ;
    }
}//end Employees namespace



int main ( )
{
    TitledEmployee frank ;
    TitledEmployee bob ( "Bobby Goodsworth" , "Sir" , "123-45-6789" , 2500.00 ) ;

    frank.setTitle ( "Mr." ) ;

    return 0 ;
}

That's because you've got it buried in the Employees namespace. Use its full name: Employees::TitledEmployee frank; Have fun.

commented: Thanks for the C++ help! +4

Ok, I just took the namespace out completely. Now i get this

1>assign18.obj : error LNK2028: unresolved token (0A00032B) "public: void __thiscall TitledEmployee::setTitle(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?setTitle@TitledEmployee@@$$FQAEXV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "int __cdecl main(void)" (?main@@$$HYAHXZ)

edit] maybe because I didn't define it.

That's just the compiler's obnoxious way of saying that you declared a method named TitledEmployee::setTitle but didn't define it anywhere.

What compiler are you using, BTW?

Visual C++ Express

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.