I am writing a program, probably the longest one I have had to do so far, and i'm just trying to get the first part running and I am having trouble, I want to take care of this before continuing with the rest since it is all very similar, I don't want to keep makign the same error. here is what i have.
#include "stdafx.h"
#include "movies.h"
#include "functions.h"
#include <fstream>
#include <iostream>
usingnamespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int id;
string name;
ofstream p;
p.open("output.txt");
CustomerData cust;
cust.count=0;
cout<<"Please enter a Customer ID: ";
cin>>id;
cout<<endl<<"Please enter a Customer Name: ";
cin>>name;
Customer cust1;
cust1.CustId =id;
cust1.CustName = name;
AddCustomer(cust, cust1);
cout<<cust.count;
return 0;
}
i get: error C2228: left of '.count' must have class/struct/union type is 'int'
i get a few of those errors, so i am thinking that it is not able to see the structs even though i link the header file in the cpp. any help is greatly appreciated.
i do know i assigned cust1.CustId and CustName in both main and in the create customer function, i was trying out different things and neither one worked.
1>c:\users\josh\documents\visual studio 2010\projects\assignment 2\assignment 2\functions.cpp(1): warning C4627: '#include "movies.h"': skipped when looking for precompiled header use
1> Add directive to 'StdAfx.h' or rebuild precompiled header
1>c:\users\josh\documents\visual studio 2010\projects\assignment 2\assignment 2\functions.cpp(2): warning C4627: '#include "functions.h"': skipped when looking for precompiled header use
1> Add directive to 'StdAfx.h' or rebuild precompiled header
1>c:\users\josh\documents\visual studio 2010\projects\assignment 2\assignment 2\functions.cpp(17): fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "StdAfx.h"' to your source?
1> Assignment 2.cpp
1>c:\users\josh\documents\visual studio 2010\projects\assignment 2\assignment 2\movies.h(4): error C2011: 'Customer' : 'struct' type redefinition
1> c:\users\josh\documents\visual studio 2010\projects\assignment 2\assignment 2\movies.h(4) : see declaration of 'Customer'
1>c:\users\josh\documents\visual studio 2010\projects\assignment 2\assignment 2\movies.h(9): error C2011: 'Movie' : 'struct' type redefinition
1> c:\users\josh\documents\visual studio 2010\projects\assignment 2\assignment 2\movies.h(9) : see declaration of 'Movie'
1>c:\users\josh\documents\visual studio 2010\projects\assignment 2\assignment 2\movies.h(14): error C2011: 'Rental' : 'struct' type redefinition
1> c:\users\josh\documents\visual studio 2010\projects\assignment 2\assignment 2\movies.h(14) : see declaration of 'Rental'
1>c:\users\josh\documents\visual studio 2010\projects\assignment 2\assignment 2\movies.h(19): error C2011: 'CustomerData' : 'struct' type redefinition
1> c:\users\josh\documents\visual studio 2010\projects\assignment 2\assignment 2\movies.h(19) : see declaration of 'CustomerData'
1>c:\users\josh\documents\visual studio 2010\projects\assignment 2\assignment 2\movies.h(24): error C2011: 'MovieData' : 'struct' type redefinition
1> c:\users\josh\documents\visual studio 2010\projects\assignment 2\assignment 2\movies.h(24) : see declaration of 'MovieData'
1>c:\users\josh\documents\visual studio 2010\projects\assignment 2\assignment 2\movies.h(29): error C2011: 'RentalData' : 'struct' type redefinition
1> c:\users\josh\documents\visual studio 2010\projects\assignment 2\assignment 2\movies.h(29) : see declaration of 'RentalData'
1>c:\users\josh\documents\visual studio 2010\projects\assignment 2\assignment 2\assignment 2.cpp(17): error C2079: 'cust' uses undefined struct 'CustomerData'
1>c:\users\josh\documents\visual studio 2010\projects\assignment 2\assignment 2\assignment 2.cpp(18): error C2228: left of '.count' must have class/struct/union
1> type is 'int'
1>c:\users\josh\documents\visual studio 2010\projects\assignment 2\assignment 2\assignment 2.cpp(56): error C2079: 'cust1' uses undefined struct 'Customer'
1>c:\users\josh\documents\visual studio 2010\projects\assignment 2\assignment 2\assignment 2.cpp(57): error C2228: left of '.CustId' must have class/struct/union
1> type is 'int'
1>c:\users\josh\documents\visual studio 2010\projects\assignment 2\assignment 2\assignment 2.cpp(58): error C2228: left of '.CustName' must have class/struct/union
1> type is 'int'
1>c:\users\josh\documents\visual studio 2010\projects\assignment 2\assignment 2\assignment 2.cpp(59): error C2664: 'AddCustomer' : cannot convert parameter 1 from 'int' to 'CustomerData'
1> Source or target has incomplete type
1>c:\users\josh\documents\visual studio 2010\projects\assignment 2\assignment 2\assignment 2.cpp(61): error C2228: left of '.count' must have class/struct/union
1> type is 'int'
and i don't believe that i defined an overloaded operator for '='?, tbh, not 100% sure what that means. i REALLY appreciate the help and look forward to paying it forward when i am able to. i am a beginner but really enjoy coding and i see it being a profession i would enjoy.
From looking at the original post, I can see various problems right off the bat:
1) Using directives in a header file are a bad idea. Not verboten, per se, but not recommended.
2) You have no dynamically allocated customers. This is fine, really, except that you'll only have 1 customer...ever.
3) You're not using include guards, so I can only assume that your header files are being included twice. This could cause the compiler to think that you're redefining your structures at compile time.
I am not supposed to edit the stdafx header, if i have #include <string> only in the main cpp, then i can't use strings in my struct header file. i am convinced now my problem is with all these includes and headers but i am required to split up all the structs in one header, function prototypes in another header, fucntion definitions in a cpp file and then main in another cpp file.
and how would i solve this:
2) You have no dynamically allocated customers. This is fine, really, except that you'll only have 1 customer...ever.
i have to initialize the array of customers? i thought that happened when i created an instance of the struct.
You can't use header guards but you're required to use precompiled-headers. You must have had the same professor I did.
Anyone care to point some issues there?
@ OP: Do this. In the main file, remove the include for #include "movies.h" . Because you don't have a header guard, it's being included twice because it's also included in the function prototypes. Generally, this would be fine and *even considered good practice to explicitly include the header defining types* but whatever. This should fix issues with redefinitions. After that, your structs should be properly defined. Give us the error list after that, if any.
have some new problems now, i'm sure it is coming from a similar issue with me including something that i shouldnt' be. i also have been adding to the project while trying to debug. here is everything i have now.
function headers:
and the errors:
1>c:\users\josh\documents\visual studio 2010\projects\assignment 2\assignment 2\functions.cpp(1): warning C4627: '#include "movies.h"': skipped when looking for precompiled header use
1> Add directive to 'StdAfx.h' or rebuild precompiled header
1>c:\users\josh\documents\visual studio 2010\projects\assignment 2\assignment 2\functions.cpp(2): warning C4627: '#include "functions.h"': skipped when looking for precompiled header use
1> Add directive to 'StdAfx.h' or rebuild precompiled header
1>c:\users\josh\documents\visual studio 2010\projects\assignment 2\assignment 2\functions.cpp(5): error C2146: syntax error : missing ';' before identifier 'CreateCustomer'
1>c:\users\josh\documents\visual studio 2010\projects\assignment 2\assignment 2\functions.cpp(5): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\josh\documents\visual studio 2010\projects\assignment 2\assignment 2\functions.cpp(5): error C2061: syntax error : identifier 'string'
1>c:\users\josh\documents\visual studio 2010\projects\assignment 2\assignment 2\functions.cpp(6): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\josh\documents\visual studio 2010\projects\assignment 2\assignment 2\functions.cpp(7): error C2146: syntax error : missing ';' before identifier 'cust1'
1>c:\users\josh\documents\visual studio 2010\projects\assignment 2\assignment 2\functions.cpp(7): error C2065: 'cust1' : undeclared identifier
1>c:\users\josh\documents\visual studio 2010\projects\assignment 2\assignment 2\functions.cpp(8): error C2065: 'cust1' : undeclared identifier
1>c:\users\josh\documents\visual studio 2010\projects\assignment 2\assignment 2\functions.cpp(8): error C2228: left of '.CustId' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\josh\documents\visual studio 2010\projects\assignment 2\assignment 2\functions.cpp(9): error C2065: 'cust1' : undeclared identifier
1>c:\users\josh\documents\visual studio 2010\projects\assignment 2\assignment 2\functions.cpp(9): error C2228: left of '.CustName' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\josh\documents\visual studio 2010\projects\assignment 2\assignment 2\functions.cpp(9): error C2065: 'custname' : undeclared identifier
1>c:\users\josh\documents\visual studio 2010\projects\assignment 2\assignment 2\functions.cpp(10): error C2065: 'cust1' : undeclared identifier
1>c:\users\josh\documents\visual studio 2010\projects\assignment 2\assignment 2\functions.cpp(13): error C2146: syntax error : missing ';' before identifier 'CreateRental'
1>c:\users\josh\documents\visual studio 2010\projects\assignment 2\assignment 2\functions.cpp(13): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\josh\documents\visual studio 2010\projects\assignment 2\assignment 2\functions.cpp(13): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\josh\documents\visual studio 2010\projects\assignment 2\assignment 2\functions.cpp(14): error C2447: '{' : missing function header (old-style formal list?)
1>c:\users\josh\documents\visual studio 2010\projects\assignment 2\assignment 2\functions.cpp(42): fatal error C1004: unexpected end-of-file found
1> Assignment 2.cpp
1>c:\users\josh\documents\visual studio 2010\projects\assignment 2\assignment 2\movies.h(7): error C2146: syntax error : missing ';' before identifier 'CustName'
1>c:\users\josh\documents\visual studio 2010\projects\assignment 2\assignment 2\movies.h(7): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\josh\documents\visual studio 2010\projects\assignment 2\assignment 2\movies.h(7): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\josh\documents\visual studio 2010\projects\assignment 2\assignment 2\movies.h(12): error C2146: syntax error : missing ';' before identifier 'MovieName'
1>c:\users\josh\documents\visual studio 2010\projects\assignment 2\assignment 2\movies.h(12): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\josh\documents\visual studio 2010\projects\assignment 2\assignment 2\movies.h(12): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\josh\documents\visual studio 2010\projects\assignment 2\assignment 2\functions.h(6): error C2061: syntax error : identifier 'string'
1>c:\users\josh\documents\visual studio 2010\projects\assignment 2\assignment 2\functions.h(12): error C2065: 'ofstream' : undeclared identifier
1>c:\users\josh\documents\visual studio 2010\projects\assignment 2\assignment 2\functions.h(12): error C2065: 'q' : undeclared identifier
1>c:\users\josh\documents\visual studio 2010\projects\assignment 2\assignment 2\functions.h(12): error C2059: syntax error : 'const'
1>c:\users\josh\documents\visual studio 2010\projects\assignment 2\assignment 2\functions.h(14): error C2065: 'ofstream' : undeclared identifier
1>c:\users\josh\documents\visual studio 2010\projects\assignment 2\assignment 2\functions.h(14): error C2065: 'q' : undeclared identifier
1>c:\users\josh\documents\visual studio 2010\projects\assignment 2\assignment 2\functions.h(14): error C2059: syntax error : 'const'
1>c:\users\josh\documents\visual studio 2010\projects\assignment 2\assignment 2\functions.h(16): error C2065: 'ofstream' : undeclared identifier
1>c:\users\josh\documents\visual studio 2010\projects\assignment 2\assignment 2\functions.h(16): error C2065: 'q' : undeclared identifier
1>c:\users\josh\documents\visual studio 2010\projects\assignment 2\assignment 2\functions.h(16): error C2059: syntax error : 'const'
1>c:\users\josh\documents\visual studio 2010\projects\assignment 2\assignment 2\functions.h(20): error C2061: syntax error : identifier 'string'
1>c:\users\josh\documents\visual studio 2010\projects\assignment 2\assignment 2\assignment 2.cpp(40): error C2039: 'CustName' : is not a member of 'Customer'
1> c:\users\josh\documents\visual studio 2010\projects\assignment 2\assignment 2\movies.h(5) : see declaration of 'Customer'
Just as a general rule, I would advise against adding new functions that invariably will have the same erros until you've actually resolved the errors that you already have.
Well it has something to do with the precompiled header. Since I think precompiled headers are slightly retarded and I've used it only once with GCC (which was not even fucking CLOSE to worth the amount of trouble I put into it), I have no idea what the issue is.