Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

double structures

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
If I use the structures here,

struct SNumeric
{
long nums[10];
}

struct SString
{
char car [10];
}

How would I create a function that when invoked with a SNumeric argument, prints the 10 elements one per line, but when a SString argument, prints all the chars in car on one line seperated by spaces.
 
#include <iostream>

#define MAX_ELEMS 10

struct SNumeric
{
long lNums[MAX_ELEMS];
};

struct SString
{
char cCar[MAX_ELEMS];
};

void outPut( const SNumeric&,int );
void outPut( const SString&,int );

int main()
{
SNumeric sn;
SString ss;

memset( &sn,0,sizeof( sn ) );
memset( &ss,1,sizeof( ss ) );

outPut( sn,MAX_ELEMS );
std::cout<<std::endl;
outPut( ss,MAX_ELEMS );
std::cout<<std::endl;

return 0;
}


void outPut( const SNumeric& s,int iElems )
{
for( int i=0;i<iElems;i++ )
std::cout << s.lNums <<
std::endl;
}


void outPut( const SString& s,int iElems )
{
for( int i=0;i<iElems;i++ )
std::cout << s.cCar
<< &quot; &quot;;
}


Overload a couple functions. Mike L.G.
mlg400@linuxmail.org
 
How would I create a function do the following when invoked by a SNumeric or a SString argument is passed to it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top