Mail Archives: djgpp/1999/12/17/10:34:11
On 17 Dec 99, at 9:53, Joanna Baldacci
<jbaldacci AT dial DOT pipex DOT com> wrote:
> code and error messages are included. the errors are generated when I add
> 'char name[]' to the customer header in the protected section. sorry if this
> seems like loads but i'm not sure where the problem is coming from. Like I
> said, its fine without the 'name' declaration,
Heya Joanna,
I had a look at your code and I found the following errors.
1. custs.h- no semicolon at the end of class declaration therefore
you will be getting a lot of irrelevan't errors just because of missing
a semicolon.
2. custs.h - no #endif at the end of custs.h.
3. custs.cpp - no return type in getcustomer(int i)
4. custs.cpp -no braces at the end of destructor ~customers()
5. extra braces (why ???) at the end of the test program
after these changes it compiled and ran perfectly.
BTW when you add "char name[]" please make sure you add a
semicolon after it as "char name[];" because dropping a semicolon
say at the end of a class gives rise to a whole lot of
incomprehensible errors by the compiler which tends to hide where
the problem really is.
please see below for the changes
Regards,
Kalum.
Enjoy DJGPP!
> ************************
> Custs.h
> ***************************
>
> # ifndef CUSTS_H
> #define CUSTS_H
>
> #include<iostream.h>
> #include "Customer.h"
>
>
> class customers
> {
> public:
> customers();
> ~customers();
> customer getCustomer(int i);
> void setCustomer(customer c,int i);
>
> private:
> customer array_of_customers[25];
> };
^^^ you haven't added a semicolon so you will be getting a lot of
parse errors.
#endif
^^^ no #endif therefore "unterminated if conditional"
>
> *******************************************
> Custs.cc;
> ******************************************
>
> #include"Custs.h"
>
> customers::customers()
> {
>
> }
>
> customer customers::getCustomer(int i)
> {
> cout<<"in getCustomer"<<endl;
> cout<<array_of_customers[i].getnumber();
return array_of_customers[i]; // <- no return type included
> }
>
> void customers::setCustomer(customer c,int i)
> {
> array_of_customers[i]=c;
> }
>
>
> customers::~customers()
{} //<--no braces included
>
> ****************************************
> test program
> **********************************************
> # include <iostream.h>
> # include "Customer.h"
> # include "Custs.h"
>
> int main()
> {
> int a, b;
> customers shoppers;
> customer dave;
> dave.setnumber(7);
> dave.display();
> cout<<"dave is a customer whose number is ";
> cout<< dave.getnumber() <<endl;
> dave.display();
> dave.setnumber(4);
> cout<<"dave is a customer whose number is ";
> cout<< dave.getnumber() <<endl;
>
>
>
>
> customer x;
> x.setnumber(1);
>
> customer y;
> cout<<"enter customer number"<<endl;
> cin>>b;
>
> y.setnumber(b);
>
> //This is rather crude but it demonstrates the approach needed
> shoppers.setCustomer(dave,1);
> shoppers.setCustomer(x,2);
> shoppers.setCustomer(y,3);
>
> cout<<"first in array is";
> shoppers.getCustomer(1);
> cout<<"second in array is";
> shoppers.getCustomer(2);
> cout<<"third in array is";
> shoppers.getCustomer(3);
> cout<<endl;
>
>
>
> cout<<"enter number to end";
> cin>>a;
> return 0;
>
> }
>
>
> {
// <-extra braces ??
> }
>
- Raw text -