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
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";
- Is method-2 wrong in some way ?
- What is the difference between the two ?
- 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