Is it appropriate to set a value to a "const char *" in the header file

Posted by sud on Stack Overflow See other posts from Stack Overflow or by sud
Published on 2010-05-21T04:23:52Z Indexed on 2010/05/21 4:30 UTC
Read the original article Hit count: 272

Filed under:
|
|

I have seen people using 2 methods to declare and define char *

Medhod-1: The header file has the below const char* COUNTRY_NAME_USA = "USA";

Medhod-2:
The header file has the below declaration const char* COUNTRY_NAME_USA; The cpp file has the below defintion : const char* COUNTRY_NAME_USA = "USA";

  1. Is method-2 wrong in some way ?
  2. What is the difference between the two ?
  3. I understand the difference between "const char * const var" , and "const char * var". If in the above methods if a "const char * const var" is declared and defined in the header as in method 1 will it make sense ?

© Stack Overflow or respective owner

Related posts about c++

Related posts about const-char