Crunch Time, Need Help (C++)

Wanna understand E=mc2, English grammer, or maybe just build a computer? We can help!

Moderator: Moderators

Post Reply
LoSTimberWolf
Inmate
Posts: 128
Joined: Sun Jan 27, 2002 4:17 pm

Crunch Time, Need Help (C++)

Post by LoSTimberWolf »

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>&nbsp &nbsp &nbsp &nbsp protected:<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp //Variables<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp char &empName;<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp char &sSN;<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp char &EmpNum;<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp char &HireDate;<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp //Validations and Errors<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp void memError ();<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp int sSNvalid ();<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp void sSNinvalid ();<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp int enValid ();<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp void enInvalid ();<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp int HireDateValid ();<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp void HireDateInvalid ();<br><br>&nbsp &nbsp &nbsp &nbsp public:<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp //Employee (char&);<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp //Employee (char&, char&);<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp //Employee (char&, char&, char&);<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp Employee (char&, char&, char&, char&);<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp //Set Functions<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp void setEmployeeName (char&);<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp void setSocialSecurityNumber (char&);<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp void setEmplyeeNumber (char&);<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp void setHireDate (char&);<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp //Get Functions<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp char& getEmployeeName ();<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp char& getSSN ();<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp char& getEmpNum ();<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp char& getHireDate ();<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp //Destructor<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp //~Employee () {delete &empName;};<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp //~Employee () {delete &empName; delete &sSN;};<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp //~Employee () {delete &empName; delete &sSN; delete &EmpNum;};<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp ~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>&nbsp &nbsp &nbsp &nbsp int len = 0;<br><br>&nbsp &nbsp &nbsp &nbsp //Employee Name Is Inputted<br>&nbsp &nbsp &nbsp &nbsp len = strlen(&empNameM);<br>&nbsp &nbsp &nbsp &nbsp empName = new char[len + 1];<br>&nbsp &nbsp &nbsp &nbsp if (&empName == NULL)<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp {<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp memError();<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp }<br>&nbsp &nbsp &nbsp &nbsp strcpy(&empName, &empNameM);<br><br>&nbsp &nbsp &nbsp &nbsp //Social Security Number Is Inputted & Tested<br>&nbsp &nbsp &nbsp &nbsp len = strlen(&sSNM);<br>&nbsp &nbsp &nbsp &nbsp sSN = new char[len + 1];<br>&nbsp &nbsp &nbsp &nbsp if (&sSN == NULL)<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp {<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp memError();<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp }<br>&nbsp &nbsp &nbsp &nbsp strcpy(&sSN, &sSNM);<br>&nbsp &nbsp &nbsp &nbsp if (sSNvalid() == 0)<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp {<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp sSNinvalid();<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp }<br><br>&nbsp &nbsp &nbsp &nbsp //Employee Number Is Inputted & Tested<br>&nbsp &nbsp &nbsp &nbsp len = strlen(&EmpNumM);<br>&nbsp &nbsp &nbsp &nbsp EmpNum = new char[len + 1];<br>&nbsp &nbsp &nbsp &nbsp if (&EmpNum == NULL)<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp {<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp memError();<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp }<br>&nbsp &nbsp &nbsp &nbsp strcpy(&EmpNum, &EmpNumM);<br>&nbsp &nbsp &nbsp &nbsp if (enValid() == 0)<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp {<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp enInvalid();<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp }<br><br>&nbsp &nbsp &nbsp &nbsp //Hire Date Is Inputter<br>&nbsp &nbsp &nbsp &nbsp len = strlen(&HireDateM);<br>&nbsp &nbsp &nbsp &nbsp HireDate = new char[len + 1];<br>&nbsp &nbsp &nbsp &nbsp if (&HireDate == NULL)<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp {<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp memError();<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp }<br>&nbsp &nbsp &nbsp &nbsp strcpy(&HireDate, &HireDateM);<br>&nbsp &nbsp &nbsp &nbsp if (HireDateValid() == 0)<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp {<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp HireDateInvalid();<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp }<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>
User avatar
XMEN Gambit
Site Admin
Posts: 4122
Joined: Thu Nov 18, 1999 12:00 am

Re: Crunch Time, Need Help (C++)

Post by XMEN Gambit »

I think your problem is in the references. In the declarations for class Employee, change <br><br>char &empName;<br><br>to <br><br>char *empName;<br><br>and see what happens. <!--EZCODE EMOTICON START :) --><img src=http://www.ezboard.com/images/emoticons/smile.gif ALT=":)"><!--EZCODE EMOTICON END--> Same for the other three variables, of course. <br> <p><!--EZCODE IMAGE START--><img src="http://www.xmenclan.org/xmengambit.gif"/><!--EZCODE IMAGE END--><br>XMEN member<br>Card-carrying DTM<br>OKL Fish-napper<br><br>Though a program be but three lines long, someday it will have to be maintained.<br><!--EZCODE ITALIC START--><em> The Tao of Programming</em><!--EZCODE ITALIC END--></p><i></i>
Image
LoSTimberWolf
Inmate
Posts: 128
Joined: Sun Jan 27, 2002 4:17 pm

Re: Crunch Time, Need Help (C++)

Post by LoSTimberWolf »

Thanks that was it. Not use to using the star. Well I fixed all the other problems but when I tried to run the computer came up and asked to send an error report. Not much longer till its due but since it runs I will get 8 out of 10 points. <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>
User avatar
XMEN Gambit
Site Admin
Posts: 4122
Joined: Thu Nov 18, 1999 12:00 am

Re: Crunch Time, Need Help (C++)

Post by XMEN Gambit »

References (&) and pointers (*, ->) are TERRIBLY important to a C programmer. They're also the cause of more errors than any other feature, since you can write or read memory areas that have nothing to do with your program.<br><br>You need to understand what they are, what they represent, and what your code does to those memory spaces. If you don't learn anything else about C, learn pointers/memory management. <p><!--EZCODE IMAGE START--><img src="http://www.xmenclan.org/xmengambit.gif"/><!--EZCODE IMAGE END--><br>XMEN member<br>Card-carrying DTM<br>OKL Fish-napper<br><br>Though a program be but three lines long, someday it will have to be maintained.<br><!--EZCODE ITALIC START--><em> The Tao of Programming</em><!--EZCODE ITALIC END--></p><i></i>
Image
BlackRider
Inmate
Posts: 966
Joined: Thu Jan 17, 2002 5:26 pm

Re: Crunch Time, Need Help (C++)

Post by BlackRider »

Just out of boredom in my C++ classes I would write simple programs that would read and display the contents of memory. You find mostly garbage looking characters but there is plenty in the way of interesting strings of text in there.... <p><!--EZCODE FONT START--><span style="color:red;font-size:large;">C</span><!--EZCODE FONT END--><!--EZCODE FONT START--><span style="color:orange;font-size:large;">O</span><!--EZCODE FONT END--><!--EZCODE FONT START--><span style="color:green;font-size:large;">L</span><!--EZCODE FONT END--><!--EZCODE FONT START--><span style="color:blue;font-size:large;">O</span><!--EZCODE FONT END--><!--EZCODE FONT START--><span style="color:indigo;font-size:large;">R</span><!--EZCODE FONT END--><!--EZCODE FONT START--><span style="color:violet;font-size:large;">S</span><!--EZCODE FONT END--><!--EZCODE FONT START--><span style="color:pink;font-size:xx-large;">!</span><!--EZCODE FONT END--></p><i></i>
User avatar
XMEN Gambit
Site Admin
Posts: 4122
Joined: Thu Nov 18, 1999 12:00 am

Re: Crunch Time, Need Help (C++)

Post by XMEN Gambit »

Ya. You can cause protection faults on Windows systems that way, too. <!--EZCODE EMOTICON START :) --><img src=http://www.ezboard.com/images/emoticons/smile.gif ALT=":)"><!--EZCODE EMOTICON END--> <p><!--EZCODE IMAGE START--><img src="http://www.xmenclan.org/xmengambit.gif"/><!--EZCODE IMAGE END--><br>XMEN member<br>Card-carrying DTM<br>OKL Fish-napper<br><br>Though a program be but three lines long, someday it will have to be maintained.<br><!--EZCODE ITALIC START--><em> The Tao of Programming</em><!--EZCODE ITALIC END--></p><i></i>
Image
Post Reply