Note that there are some explanatory texts on larger screens.

plurals
  1. POSetting member variables to null improperly
    primarykey
    data
    text
    <p>I think I'm declaring everything correctly yet I'm getting undeclared identifiers in lines 22-26 in main.cpp. I'm also getting this = is ambiguous in line 12-16 in my employee.cpp. I also have a weird expression must have pointer to object type for salary in line 55 of employee.cpp. I'd really appreciate any help since my school doesn't have a tutor at the moment.</p> <pre><code>//Employee.h using namespace std; class Employee { private: public: string FirstName; string LastName; string DisplayFirstName; string DisplayLastName; string DisplaySalary; string SearchName; float Salary; Employee( string FirstName, string LastName, float Salary ) { setFirstName(FirstName); setLastName(LastName); setSalary(Salary); } string setFirstName(string FirstName); string setLastName(string LastName); float setSalary(float Salary); void ReadFile(ifstream&amp; MyinFile, string FirstName, string LastName, float Salary); string EmployeeSearch(string LastName[], string SearchName); void DisplayEmployee (string DisplayFirstName, string DisplayLastName, string DisplaySalary); Employee(); }; //Employee.cpp #include &lt;iostream&gt; #include &lt;fstream&gt; #include &lt;string&gt; #include "Employee.h" using namespace std; string setFirstName(string FirstName) { **FirstName = NULL;** //ambiguous error } string setLastName(string LastName) { **LastName = NULL;** //ambiguous error } float setSalary(float Salary) { Salary = 0.0; } void ReadFile(ifstream&amp; MyinFile, string FirstName, string LastName, float Salary) { char exit_char; int MaxSize; int count = 0; MyinFile.open("employee.dat"); if (!MyinFile) { //no cout &lt;&lt; "Can't open input file." &lt;&lt; endl; //Tests the right file. char exit_char; //End Program cout &lt;&lt; "Press any key to exit" &lt;&lt; endl; cin &gt;&gt; exit_char; } for(count = 0; count &lt; MaxSize; count++) { MyinFile &gt;&gt; LastName[count]; MyinFile &gt;&gt; FirstName[count]; MyinFile &gt;&gt; **Salary[count];** //error } MyinFile.close(); } string EmployeeSearch(string LastName[], string FirstName[], float Salary, string SearchName, string DisplayFirstName, string DisplayLastName, string DisplaySalary) { cout &lt;&lt; "Please enter the name of the employee you would like to search." &lt;&lt; endl; cin &gt;&gt; SearchName; for (int i = 0; i &lt; 10; i++ ) { if (LastName[i] == SearchName) { DisplayFirstName = FirstName[i]; DisplayLastName = LastName[i]; DisplaySalary = **Salary[i];** //error } else cout &lt;&lt; "Could not find employee." &lt;&lt; endl; } }; void DisplayEmployee (string DisplayFirstName, string DisplayLastName, string DisplaySalary) { cout &lt;&lt; DisplayFirstName &lt;&lt; " "; cout &lt;&lt; DisplayLastName &lt;&lt; " "; cout &lt;&lt; DisplaySalary &lt;&lt; endl; }; //Main.cpp #include &lt;iostream&gt; #include &lt;fstream&gt; #include &lt;string&gt; #include "Employee.h" using namespace std; const int MaxSize = 100; int main() { char Redo; //Input a character to redo the program ifstream MyinFile; cout &lt;&lt; "Your Salary Machine\n\n"; Employee Employee; Employee.ReadFile(**MyinFile, FirstName, LastName, Salary**); //undeclared identifier error do { Employee.EmployeeSearch(**LastName[], SearchName**); //undeclared identifier error Employee.DisplayEmployee(**DisplayFirstName,DisplayLastName,DisplaySalary**); //undeclared identifier error //Asks user if they want redo the program cout &lt;&lt; "Would you like to redo the program?\n"; cout &lt;&lt; "Please enter Y or N: \n"; cin &gt;&gt; Redo; }while(Redo == 'Y' || Redo == 'y'); return 0; } </code></pre> <p>The program is written to read a file that has a first and last name then salary then be able to type in the last name of whoever is in the file and it will display the name and salary and then repeat. I'm suppose to use a constructor to initialize the first and last name as NULL and then the salary as 0.0. I'm also supposed to use get and set member functions.</p> <p>Here are the errors:</p> <pre><code>------ Build started: Project: Lab3Project, Configuration: Debug Win32 ------ Main.cpp \\psf\home\documents\visual studio 2010\projects\csci112\lab3project\lab3project\main.cpp(22): error C2065: 'FirstName' : undeclared identifier \\psf\home\documents\visual studio 2010\projects\csci112\lab3project\lab3project\main.cpp(22): error C2065: 'LastName' : undeclared identifier \\psf\home\documents\visual studio 2010\projects\csci112\lab3project\lab3project\main.cpp(22): error C2065: 'Salary' : undeclared identifier \\psf\home\documents\visual studio 2010\projects\csci112\lab3project\lab3project\main.cpp(25): error C2065: 'SearchName' : undeclared identifier \\psf\home\documents\visual studio 2010\projects\csci112\lab3project\lab3project\main.cpp(25): error C3861: 'LastName': identifier not found \\psf\home\documents\visual studio 2010\projects\csci112\lab3project\lab3project\main.cpp(26): error C2065: 'DisplayFirstName' : undeclared identifier \\psf\home\documents\visual studio 2010\projects\csci112\lab3project\lab3project\main.cpp(26): error C2065: 'DisplayLastName' : undeclared identifier \\psf\home\documents\visual studio 2010\projects\csci112\lab3project\lab3project\main.cpp(26): error C2065: 'DisplaySalary' : undeclared identifier Employee.cpp \\psf\home\documents\visual studio 2010\projects\csci112\lab3project\lab3project\employee.cpp(12): error C2593: 'operator =' is ambiguous c:\program files\microsoft visual studio 10.0\vc\include\xstring(772): could be 'std::basic_string&lt;_Elem,_Traits,_Ax&gt; &amp;std::basic_string&lt;_Elem,_Traits,_Ax&gt;::operator =(_Elem)' with [ _Elem=char, _Traits=std::char_traits&lt;char&gt;, _Ax=std::allocator&lt;char&gt; ] c:\program files\microsoft visual studio 10.0\vc\include\xstring(767): or 'std::basic_string&lt;_Elem,_Traits,_Ax&gt; &amp;std::basic_string&lt;_Elem,_Traits,_Ax&gt;::operator =(const _Elem *)' with [ _Elem=char, _Traits=std::char_traits&lt;char&gt;, _Ax=std::allocator&lt;char&gt; ] while trying to match the argument list '(std::string, int)' \\psf\home\documents\visual studio 2010\projects\csci112\lab3project\lab3project\employee.cpp(16): error C2593: 'operator =' is ambiguous c:\program files\microsoft visual studio 10.0\vc\include\xstring(772): could be 'std::basic_string&lt;_Elem,_Traits,_Ax&gt; &amp;std::basic_string&lt;_Elem,_Traits,_Ax&gt;::operator =(_Elem)' with [ _Elem=char, _Traits=std::char_traits&lt;char&gt;, _Ax=std::allocator&lt;char&gt; ] c:\program files\microsoft visual studio 10.0\vc\include\xstring(767): or 'std::basic_string&lt;_Elem,_Traits,_Ax&gt; &amp;std::basic_string&lt;_Elem,_Traits,_Ax&gt;::operator =(const _Elem *)' with [ _Elem=char, _Traits=std::char_traits&lt;char&gt;, _Ax=std::allocator&lt;char&gt; ] while trying to match the argument list '(std::string, int)' \\psf\home\documents\visual studio 2010\projects\csci112\lab3project\lab3project\employee.cpp(40): error C2109: subscript requires array or pointer type \\psf\home\documents\visual studio 2010\projects\csci112\lab3project\lab3project\employee.cpp(55): error C2109: subscript requires array or pointer type </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload