user1876942
user1876942

Reputation: 1501

Best way to design this code?

I have a log function which takes a parameter, which prints out the name of some HW

logEvent("LOG THIS HW select = %s", NAME[selection]);

To determine what to print I have:

const char* NAME[] =
{
"A"
"B"
} 

This was in the header but then I got multiple implementations problems, I want this to be accessed by many files. How can I put this kind of data in a header?

Upvotes: 0

Views: 70

Answers (2)

molbdnilo
molbdnilo

Reputation: 66371

You put a declaration in the header:

extern const char* NAME[];

and put the definition in one cpp file:

const char* NAME[] = {"A", "B"}; 

Upvotes: 3

Bathsheba
Bathsheba

Reputation: 234715

Adjust logEvent so selection is passed as a parameter. You can then keep the string table local to that function.

Upvotes: 3

Related Questions