Calling function from another class

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
class Destination
{
....
   private:
      CityNameType city;  // name of the city where the packages are sent
      int package_count;  // count of packages
      float total_weight; // weight of all packages for this city
      float packageWeightSum;   // total weight of all packages
      int packageCountSum;    // total count of all packages
   public:
// print out the fields of the destination, appropriately labeled and formatted.
   void PrintDest( DestinationList & destB  ) const
   {
      destB.PrintCityName(true);
      cout << setw(4) << right <<  package_count << right 
			 << " packages weighing" << setw(11) << right << total_weight 
		        << right << " pounds";
   }  

class DestinationList 
{
   private:
      int num;                       // number of objects in the list
      Destination list[MAX_CITIES];  // array of destinations
   public:

// Method to print city in uppercase. The parameter rightjustify is
   // set to true when used to print in table form. Table form means
   // the name is right justified when printed. The parameter is
   // set to false when used to print in messages.
   // params: IN
   void PrintCityName( bool rightjustify ) const
   {
      CityNameType ucity;
      strcpy(ucity, city);
      ToUpper(ucity);
         
	{
	   cout << setw(19) << right << ucity;
	}
     else 
      cout << city;
   }
  
  //
  void Summarize( )
  {
     for (int i = 0; i < num; i++)
     {
        list[i].PrintDest();
        cout << endl;
     }
  }


I'm having trouble calling PrintCityName from PrintDest, the problem is that they are in 2 different classes, yet this has to be because of the private variables needed from both classes.

The idea is that PrintCityName converts a city name into uppercase, which is used inside of the PrintDest function to print a single line of info. Then, the Summarize function loops, printing out a line for each city in the list.

How do I call PrintCityName in the other class function?
bmxtrev wrote:
I'm having trouble calling PrintCityName from PrintDest
Are you sure it's not the other way around? This makes no sense.
I'm trying to use the PrintCityName function inside of the PrintDest function, which is in a different class than PrintCityName.

PrintCityName converts a city name to uppercase, which is then part of the output of PrintDest, which also outputs 2 data items from it's own class.
Why is PrintCityName in DestinaionList? It doesn't use any of the members, it could be static or it could even be outside of the class completely.
Topic archived. No new replies allowed.