Hi,
I want to write a Generic Method which will display both Integer and Char array.
My Sample Program Goes Below:
=============== =========
#include<iostre am>
using namespace std;
void displayInt(int* intArray)
{
for(int i = 0 ;i< 5;)
cout<<intArray[i++]<<endl;
}
void displayChar(cha r* charArray)
{
for(int i = 0 ;i< 5;)
cout<<charArray[i++]<<endl;
}
int main()
{
int intArray[] = {1,2,3,4,5};
char charArray[] = {'a','b','c','d ','e'};
cout<<"Displayi ng Integer Array :"<<endl;
int* intArr = (int*) intArray;
displayInt(intA rr);
cout<<"Displayi ng Character Array:"<<endl;
char* charArr = (char*) charArray;
displayChar(cha rArr);
return 0;
}
But I want to write a single function lets say
void display(void* vArray)
{
for(int i = 0 ;i< 5;)
cout<<vArray[i++]<<endl;
}
instead of
displayInt(int* intArray) and displayChar(cha r* charArray).
What I should do for the same?
Thanking you in advance.
I want to write a Generic Method which will display both Integer and Char array.
My Sample Program Goes Below:
=============== =========
#include<iostre am>
using namespace std;
void displayInt(int* intArray)
{
for(int i = 0 ;i< 5;)
cout<<intArray[i++]<<endl;
}
void displayChar(cha r* charArray)
{
for(int i = 0 ;i< 5;)
cout<<charArray[i++]<<endl;
}
int main()
{
int intArray[] = {1,2,3,4,5};
char charArray[] = {'a','b','c','d ','e'};
cout<<"Displayi ng Integer Array :"<<endl;
int* intArr = (int*) intArray;
displayInt(intA rr);
cout<<"Displayi ng Character Array:"<<endl;
char* charArr = (char*) charArray;
displayChar(cha rArr);
return 0;
}
But I want to write a single function lets say
void display(void* vArray)
{
for(int i = 0 ;i< 5;)
cout<<vArray[i++]<<endl;
}
instead of
displayInt(int* intArray) and displayChar(cha r* charArray).
What I should do for the same?
Thanking you in advance.
Comment