..for manipulation in the main part of the program.

Basically Im trying to create a Class function that asks the user to enter in 3 different teams and their nationalities and then redisplay them when the main calls that function.

struct squadre {
			string teamn;
			string nat;
			} clube [N_TEAMS];

			Team(void); //Creates an empty Team
			clube storeTeamName();

Where N_TEAMS = 3

clube Team::storeTeamName()
	for (n=0; n<N_TEAMS; n++)
		cout << "Enter Team Name : ";
		getline (cin,clube[n].teamn);
		cout << "Enter Team Nationality : ";
		getline (cin,clube[n].nat);
        return clube;

and then the main...

Team disp; // defining the class Team
	cout << "\nYou have entered these teams:\n";
	for (n=0; n<N_TEAMS; n++)
	cout << clube[n].teamn;
	cout << " (" << clube[n].nat << " )\n";

I realise Im going to have to assign the disp.storeTeamName() to something so it can mainpulated in the main but Im having trouble working out how Id transfer the object clube of the structure back to the main program. If anyone has any ideas Id be grateful. Sorry If I havent explained myself well enough.

Ive ommitted non relevant elements of the entire program just for ease.

8 Years
Discussion Span
Last Post by Run.[it]

If I understand your question correctly, you want to return a reference to one of the structure instances inside your object:

#include <iostream>

struct block {
  int data;

class block_collection {
  static const int _size = 10;

  block _base[_size];
  int get_size() const { return _size; }
  block& get_block ( int i ) { return _base[i]; }

int main()
  block_collection blocks;

  for ( int i = 0; i < blocks.get_size(); i++ )
    blocks.get_block ( i ).data = i;

  for ( int i = 0; i < blocks.get_size(); i++ )
    std::cout<< blocks.get_block ( i ).data <<'\n';
Votes + Comments
Cheers again!

Thanks Narue, thats exactly what I meant and the push I needed.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.