What i am trying to do is pass an array of structs to a function.

the code i have so far follows:

struct Contribution
{
	string name;
	double amount;
};

const int MAX = 25;

typedef Contribution BigSpender;
typedef BigSpender ContributionRec[MAX];

const string NAME_FILE = "names.txt";
const string CONTRIBUTION_FILE = "slush.txt";

void InitProgram( BigSpender ContributionRec[MAX] );

int main()
{

	InitProgram( ContributionRec[MAX] );
	return 0;
}

void InitProgram( BigSpender& ContributionRec[MAX] )
{
	return;
}

Can anyone tell me what I am doing wrong?

Recommended Answers

All 6 Replies

struct Contribution
{
	string name;
	double amount;
};

const int MAX = 25;

typedef Contribution BigSpender[MAX];

const string NAME_FILE = "names.txt";
const string CONTRIBUTION_FILE = "slush.txt";

void InitProgram( BigSpender& ContributionRec );

int main()
{
    BigSpender ContributionRec;
	InitProgram( ContributionRec );
	return 0;
}

void InitProgram( BigSpender& ContributionRec )
{
	return;
}

thanks!

like i said before thank you, but now when i run the code i get this message

'BigSpender' does not define this operator or a conversion to a type acceptable to the predefined operator

struct Contribution
{
	string name;
	double amount;
};

const int MAX = 25;

typedef Contribution BigSpender;
typedef BigSpender ContributionRec[MAX];

const string NAME_FILE = "names.txt";
const string CONTRIBUTION_FILE = "slush.txt";

void InitProgram(BigSpender& ContributionRec);

int main()
{
BigSpender ContributionRec;

	InitProgram(ContributionRec);
	return 0;
}

void InitProgram(BigSpender& ContributionRec)
{
ifstream nameLog, contributionLog;

nameLog.open( NAME_FILE.c_str() ); // open file
contributionLog.open( CONTRIBUTION_FILE.c_str() ); // open file

	for ( int i = 0; i < MAX; i++)
	{
	nameLog >> ContributionRec[i].name;
	cout << names << endl;
	}

	nameLog.close();
	contributionLog.close();

	return;
}

delete lines 9 and 10 because that doesn't work, and replace it with just this one line typedef Contribution BigSpender[MAX];

thanks

Are all the typdef's really needed? I find it hard to follow the bouncing, er, whatever.

struct Contribution
{
	string name;
	double amount;
};

const int MAX = 25;

const string NAME_FILE = "names.txt";
const string CONTRIBUTION_FILE = "slush.txt";

void InitProgram( Contribution contrib[] );

int main()
{
    Contribution  ContributionRec[MAX];
	InitProgram( ContributionRec );
	return 0;
}

void InitProgram( Contribution contrib[] )
{
	return;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.