Crunch Time, Need Help (C++)
Posted: Thu Mar 06, 2003 9:11 am
I have been trying to figure out what is wrong and how to fix it for the past two days. I started with a 102 errors and now down to 31. The main problem is my Dynamicly allowcated memory which the compiler seems not to like. I will post the constructor in which they appear, and then some of the errors, but I will not post all of the program due to its three objects and a driver. The three objects are connected through Inheritence, and the main problem is accuring in the base object (base - derived - derived). If you need to see more of the program, just ask.<br><br><br>Here is the class ------------------------------------------<br>class Employee<br>{<br>        protected:<br>                //Variables<br>                char &empName;<br>                char &sSN;<br>                char &EmpNum;<br>                char &HireDate;<br>                //Validations and Errors<br>                void memError ();<br>                int sSNvalid ();<br>                void sSNinvalid ();<br>                int enValid ();<br>                void enInvalid ();<br>                int HireDateValid ();<br>                void HireDateInvalid ();<br><br>        public:<br>                //Employee (char&);<br>                //Employee (char&, char&);<br>                //Employee (char&, char&, char&);<br>                Employee (char&, char&, char&, char&);<br>                //Set Functions<br>                void setEmployeeName (char&);<br>                void setSocialSecurityNumber (char&);<br>                void setEmplyeeNumber (char&);<br>                void setHireDate (char&);<br>                //Get Functions<br>                char& getEmployeeName ();<br>                char& getSSN ();<br>                char& getEmpNum ();<br>                char& getHireDate ();<br>                //Destructor<br>                //~Employee () {delete &empName;};<br>                //~Employee () {delete &empName; delete &sSN;};<br>                //~Employee () {delete &empName; delete &sSN; delete &EmpNum;};<br>                ~Employee () {delete &empName; delete &sSN; delete &EmpNum; delete &HireDate;};<br>};<br>#endif;<br><br>Here is the constructor--------------------------------------<br>Employee::Employee (char &empNameM, char &sSNM, char &EmpNumM, char &HireDateM)<br>{<br>        int len = 0;<br><br>        //Employee Name Is Inputted<br>        len = strlen(&empNameM);<br>        empName = new char[len + 1];<br>        if (&empName == NULL)<br>                {<br>                memError();<br>                }<br>        strcpy(&empName, &empNameM);<br><br>        //Social Security Number Is Inputted & Tested<br>        len = strlen(&sSNM);<br>        sSN = new char[len + 1];<br>        if (&sSN == NULL)<br>                {<br>                memError();<br>                }<br>        strcpy(&sSN, &sSNM);<br>        if (sSNvalid() == 0)<br>                {<br>                sSNinvalid();<br>                }<br><br>        //Employee Number Is Inputted & Tested<br>        len = strlen(&EmpNumM);<br>        EmpNum = new char[len + 1];<br>        if (&EmpNum == NULL)<br>                {<br>                memError();<br>                }<br>        strcpy(&EmpNum, &EmpNumM);<br>        if (enValid() == 0)<br>                {<br>                enInvalid();<br>                }<br><br>        //Hire Date Is Inputter<br>        len = strlen(&HireDateM);<br>        HireDate = new char[len + 1];<br>        if (&HireDate == NULL)<br>                {<br>                memError();<br>                }<br>        strcpy(&HireDate, &HireDateM);<br>        if (HireDateValid() == 0)<br>                {<br>                HireDateInvalid();<br>                }<br>};<br><br><br>List of errors for this part of the program---------------------<br>(126) : error C2758: 'empName' : must be initialized in constructor base/member initializer list<br>(16) : see declaration of 'empName'<br>(126) : error C2758: 'sSN' : must be initialized in constructor base/member initializer list<br>(17) : see declaration of 'sSN'<br>(126) : error C2758: 'EmpNum' : must be initialized in constructor base/member initializer list<br>(1<!--EZCODE EMOTICON START 8) --><img src=http://www.ezboard.com/images/emoticons/glasses.gif ALT="8)"><!--EZCODE EMOTICON END--> : see declaration of 'EmpNum'<br>(126) : error C2758: 'HireDate' : must be initialized in constructor base/member initializer list<br>(19) : see declaration of 'HireDate'<br>(131) : error C2440: '=' : cannot convert from 'char *' to 'char'<br> This conversion requires a reinterpret_cast, a C-style cast or function-style cast<br>(140) : error C2440: '=' : cannot convert from 'char *' to 'char'<br> This conversion requires a reinterpret_cast, a C-style cast or function-style cast<br>(153) : error C2440: '=' : cannot convert from 'char *' to 'char'<br> This conversion requires a reinterpret_cast, a C-style cast or function-style cast<br>(166) : error C2440: '=' : cannot convert from 'char *' to 'char'<br> This conversion requires a reinterpret_cast, a C-style cast or function-style cast <p><!--EZCODE BOLD START--><strong>-LoS-</strong><!--EZCODE BOLD END--><!--EZCODE ITALIC START--><em>TimberWolf</em><!--EZCODE ITALIC END-->{FF}<br>Vehicle Specilist</p><i></i>