delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/12/17/10:34:11

From: "Kalum Somaratna aka Grendel" <kalum AT newmail DOT net>
To: djgpp AT delorie DOT com
Date: Fri, 17 Dec 1999 19:31:40 +0600
MIME-Version: 1.0
Subject: Re: newbie q: code and error messages. this is quite long.
CC: jbaldacci AT dial DOT pipex DOT com
In-reply-to: <83d19h$djc$1@lure.pipex.net>
X-mailer: Pegasus Mail for Win32 (v3.12)
Message-ID: <94547380401@out.newmail.net>
Reply-To: djgpp AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019