![]() |
Final project has begun! So have the errors!
Alright, so I'm finally getting this event simulation of a grocery store underway. My first goal is to get the customers created. To start this, first and last names (which will be assigned at random) need to be read in from a file and stored in 2 different string arrays, which I've done. Next, I'm in the process of creating 2 classes, one for Customer objects, and another called customerFactory which will produce all the random data and assign it to each new customer, as required by the programming project.
Before I try to code every piece of these 2 classes, I wanted to at least get the names from the files read in. I can accomplish this from main() with no problem. I decided it would be better to do it from within the constructor of the customerFactory, since an instance of this class will be creating all the customers using these names. Upon creating this customerFactory class, copying the code from main to read in the names, and making a few changes to use the data members of the factory class for storing the string arrays, when trying to create a "factory" instance inside main(), I get 4 errors that reference the built-in assert.h header. What's going on here? errors: c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\assert.h(47): error C2143: syntax error : missing ';' before 'string' c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\assert.h(47): error C2143: syntax error : missing ';' before 'string' c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\assert.h(47): fatal error C1004: unexpected end of file found c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\assert.h(47): fatal error C1004: unexpected end of file found Below is the current code for my driver, customerFactory header and implementation, and the contents of the 2 .txt files. driver: :
//CECS 302 - CODY S-----customerFactory Header: :
//CECS 302 - CODY S-----customerFactory Implementation: :
//CECS 302 - CODY S-----first names text file: :
50Last Names text file: :
50 |
Quote:
You're missing the semicolon at the end of your class definition in your customerFactory header. |
HAHA... OMG! and I thought class ending semi-colons was well instilled in my programming brain... It would be something like that to partially make my evening bad... THANK YOU AREVOS... That would have driven me nuts all night.. and thanks for the quick response, that will certainly help me get much more done tonight (and post plenty more problems, i'm sure of if it [HA])! Seriously, check back tonight, very likely to be more posts.
|
OK, everything for the customerFactory class and the relevant constructor for the customer class has been written. Now, I'm going to have to run a for loop 1000 times to create 1000 random customers.
I'm having some trouble with this part, b/c I want to create a standard c[#] instance for each customer, but it's saying no. Here's the code I have based on your suggestions: The function within the customerFactory class that passes the random data to the customer constructor: :
Customer customerFactory::newRandomCustomer()The Customer Constructor: :
Customer::Customer(string first, string last, int pay, bool deli, bool sweeps, int items, int arrival)and the driver: :
int main()I was trying to return a customer object from the customerFactory and set it equal to c[i], but I'm guessing there is an issee using the same name for instance inside the factory. Does anyone know how to make a similar method work? |
"using namespace std" in header files is not recommended. Better to expend the effort to write "std::string", etc. Also, you put your header guards below all the includes, which means you can get a lot of shit shoveled in there if the file happens to be included, somehow, twice (which is what the header guards are for, anyway).
|
Create an array of customers, and then enter the loop.
:
int main() |
Hello all,
What do you mean by working assignment operator. Do you mean I need to overload the =? As for the #ifndef, etc, I moved those up. And I know that I shouldn't use namespace std; throughout, but I won't be using any other namespace here, and to be honest I'm not even totally sure how to create other namespaces. I'm a little disappointed that my classes have yet to cover the topic. And, my main now looks like: :
int main()But I'm still getting all of these fun errors: error C2146: syntax error : missing ';' before identifier 'newRandomCustomer' error C2057: expected constant expression error C2075: 'c' : array initialization needs curly braces error C2466: cannot allocate an array of constant size 0 error C2146: syntax error : missing ';' before identifier 'newRandomCustomer' error C2146: syntax error : missing ';' before identifier 'newRandomCustomer' error C2501: 'customerFactory::Customer' : missing storage-class or type specifiers error C2501: 'customerFactory::Customer' : missing storage-class or type specifiers error C2501: 'customerFactory::Customer' : missing storage-class or type specifiers warning C4183: 'newRandomCustomer': missing return type; assumed to be a member function returning 'int' warning C4183: 'newRandomCustomer': missing return type; assumed to be a member function returning 'int' warning C4183: 'newRandomCustomer': missing return type; assumed to be a member function returning 'int' error C2371: 'customerFactory::newRandomCustomer' : redefinition; different basic types error C2556: 'Customer customerFactory::newRandomCustomer(void)' : overloaded function differs only by return type from 'int customerFactory::newRandomCustomer(void)' And I'm postive they all stem from the creation of the customers via the loop. What now? Thanks for the help guys... |
The first one sounds like a missing type or brace or something. As for the array,
:
Customer c[i] = factory.newRandomCustomer(); |
The one error, the syntax error, says I have an issue in my customerFactory class at my newRandomCustomer definition: I've commented the location:
:
//CECS 302 - CODY S-----Do you see the problem there? All errors posted below go with this line except the first one, and the last 2. main now looks like: :
int main()Here are the current errors: error C2146: syntax error : missing ';' before identifier 'newRandomCustomer' error C2679: binary '=' : no operator found which takes a right-hand operand of type 'int' (or there is no acceptable conversion) error C2146: syntax error : missing ';' before identifier 'newRandomCustomer' error C2146: syntax error : missing ';' before identifier 'newRandomCustomer' error C2501: 'customerFactory::Customer' : missing storage-class or type specifiers error C2501: 'customerFactory::Customer' : missing storage-class or type specifiers error C2501: 'customerFactory::Customer' : missing storage-class or type specifiers warning C4183: 'newRandomCustomer': missing return type; assumed to be a member function returning 'int' warning C4183: 'newRandomCustomer': missing return type; assumed to be a member function returning 'int' warning C4183: 'newRandomCustomer': missing return type; assumed to be a member function returning 'int' rror C2371: 'customerFactory::newRandomCustomer' : redefinition; different basic types error C2556: 'Customer customerFactory::newRandomCustomer(void)' : overloaded function differs only by return type from 'int customerFactory::newRandomCustomer(void)' So is it saying I'm needing an oveloaded operator. If so, for what. I'm trying to assign one object to another w/ both the same type? |
At this point,
:
Customer newRandomCustomer(); // <----------- ERROR C2146 |
| All times are GMT -5. The time now is 1:26 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC