-4

My function header is

int display_caption( char* caption ); 

if( display_caption( "hybrid thresholded Image" ) != 0 ) 
{ 
    return 0; 
}

It returns an error

Argument of type 'const char*' is incompatible with parameter of type 'char*'

Can someone help me with this ?

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • 2
    You cannot convert a pointer from `const T*` to `T*`. `display_caption` is likely meant to have a `const char*` parameter instead of a `char*`. – François Andrieux May 18 '18 at 17:30
  • Try `int display_caption(const char* caption)`. – Galik May 18 '18 at 17:32
  • 1
    Or even better, considering how you're using it: `bool display_caption(const char* caption);`. – Mike Borkland May 18 '18 at 17:48
  • What do you understand about your error? Have you identified your argument? Have you identified your parameter? Do you see how they are incompatible? As it stands, this question is asking us to guess what you don't understand about that message. – Drew Dormann May 18 '18 at 18:10

1 Answers1

0

If display_caption doesn't need to modify the caption parameter, you can change its type to const char* :

int display_caption( const char* caption );

if it does need to modify it, you will need to make a copy of the string first.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
pascx64
  • 904
  • 16
  • 31