Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

public methods help!


  • Please log in to reply

#1
Gster

Gster

    New Member

  • Member
  • Pip
  • 1 posts
I have this program that uses more than one class and it needs to access the data from the first class of private data to the next class to use that data in sorting and such. Everyone says I need a public method to let it be accessible to the second class. Problem is, I cant find anything saying what the syntax is. and we're not allowed to use inheritance for this project

here is what I have for my second class

class Tournament:public Golfer
{ private:
int total_score[];
public:

void compute_total();
void sort_name();
void final_score();

};

the golfer class has every golfer name and score in it. I just need to find a way for the tournament class to access the data. My project compiles and runs fine. it just dosent output the data sorted in the tournament class. The cout's in the tournament class work fine though.

Thank you
  • 0

Advertisements


#2
darth_ash

darth_ash

    Member 1K

  • Member
  • PipPipPipPip
  • 1,382 posts
Hi Gster,
You can't access public methods of the Golfer directly, You need to create an object of the Golfer class in Tournament class.
A better way would be to use public static methods instead.

Edited by darth_ash, 06 April 2006 - 10:14 PM.

  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP