P
pozz
I have a medium experience in C and now I'm learning C++. I have some
difficulties to think by and use classes, so with object oriented
programming.
In my application I have a configuration file that stores some
settings in non-volatile way. Several parts, modules and classes could
access the configuration file both for reading and writing settings.
In C I can create settings.h with the interface:
---
int settings_read(const char *name, char *value, size_t valuesize);
int settings_save(const char *name, const char *value);
---
Every other module that wants to use the settings facilities will
include "settings.h" and user settings_read() and settings_write().
The implementation and any additional data (such as the filename) are
hidden in settings.c.
In C++ I was trying to create a class in settings.h, but I'm not sure
if I should add private data there:
---
class Settings {
const char filename[] = "settings.ini";
public:
void Settings(void);
virtual ~Settings(void);
int settings_read(const string name, string value);
int settings_save(const string name, const string value);
};
---
Why the user should know about private data, like filename? I'm
tempted to avoid adding private data/functions in the class
declaration in settings.h, but in settings.c as typical static names
(like in C). I don't know if this is a good approach, because I have
seen many C++ source files with private names in include file.
difficulties to think by and use classes, so with object oriented
programming.
In my application I have a configuration file that stores some
settings in non-volatile way. Several parts, modules and classes could
access the configuration file both for reading and writing settings.
In C I can create settings.h with the interface:
---
int settings_read(const char *name, char *value, size_t valuesize);
int settings_save(const char *name, const char *value);
---
Every other module that wants to use the settings facilities will
include "settings.h" and user settings_read() and settings_write().
The implementation and any additional data (such as the filename) are
hidden in settings.c.
In C++ I was trying to create a class in settings.h, but I'm not sure
if I should add private data there:
---
class Settings {
const char filename[] = "settings.ini";
public:
void Settings(void);
virtual ~Settings(void);
int settings_read(const string name, string value);
int settings_save(const string name, const string value);
};
---
Why the user should know about private data, like filename? I'm
tempted to avoid adding private data/functions in the class
declaration in settings.h, but in settings.c as typical static names
(like in C). I don't know if this is a good approach, because I have
seen many C++ source files with private names in include file.