I am trying to use pointers in the following function and get the following erro
ID: 3656865 • Letter: I
Question
I am trying to use pointers in the following function and get the following error:
'myHeader' : cannot convert parameter 2 from 'int' to 'int *'
please help me debug it.
#include <iostream>
#include <string>
using namespace std;
void myHeader(string name, int *lab, string *date, int question)
{
cout<<" ***************************************************"
" "<<name<<" "
" Lab #"<<lab<<" "
" "<<date<<" "
" Question #"<<question<<" "
" ***************************************************"<<endl;
}
int main()
{
myHeader("Tom cruise", 728, "April 13", 45);
}
Explanation / Answer
You are declaring the function myHeader( string, int *, string *, int ), and then calling it with the following arguments: "Tom cruise" - a string 728 - an int (NOT an int *) "April 13" - a string (NOT a string *) 45 - an int You should change the declaration of the function to be of the form: void myHeader( string name, int lab, string date, int question ) Keep in mind that a POINTER to a string and a POINTER to an integer are not the same as a string or an integer.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.