user48730: I'm building a monitoring IP class, IPmonitoring, that using an SPIFFS class that I wrote, flashLOG. Inside IPmonitoring I have 2 instances of flashLOG (code below).
My sketch have several instances of IPmonitoring for several servicesI wish to monitor. I Wish that connectionLOG and disconnectionLOG have unique and automated names.
For example if I'm monitoring a service called MQTT its connect and disconnect log will be MQTT_discolog.txt and MQTT_conlog.txt. In my code below, filename1 and  filename2 are consts.
class IPmonitoring
{
private:
        char *_IP;
        char *_nick;

        flashLOG connectionLOG;
        flashLOG disconnectionLOG;

public:
        IPmonitoring(char *IP, char *nick, char *filename1 = "/conlog.txt", char *filename2 = "/disconlog.txt")
            : connectionLOG(filename1), disconnectionLOG(filename2)
        {
                _IP = IP;
                _nick = nick;
        }

EDIT1 - example how to use class
my goal is that filename1 for example will be MQTTbroker_connlog.txt meaning a combination of _nick and a suffix,
IPmonitoring MQTT_service("192.168.3.200","MQTTbroker");

void setup()
{
MQTT_service.start();
}

void loop()
{
MQTT_service.loop();
}


user37622: You have three options for the file names and generally.

constant string a.k.a. string literal
string buffer global or on stack with scope valid while the string is used
dynamically allocated string on heap

with 2) and 3) you can then build a string with C str or sprintf functions
option 3) is alright on MCU if you create these file names only at startup, not if you create them repeatedly as the sketch is running
If you choose option 3) you can build the strings in the constructor of IPmonitoring class, but you can't build the string in the member initialization part of the constructor. You have to add setters to flashLOG class and after building the strings for file names set them to the flashLOG instance with the setters.

user7508: Judging from your example usage, you want the filenames to be built by
the IPmonitoring constructor. However, since that class cannot know in
advance how much space is needed for the file names, you are left with
two choices:

Let those file names be data members: arrays of char of some fixed
size. This will impose a limit on the maximum file name length.

Allocate the arrays dynamically at construction time.


Here is a tentative implementation of the second approach:
class IPmonitoring
{
private:
    const char *_IP;
    const char *_nick;
    const char *connectionLOG_filename;
    const char *disconnectionLOG_filename;
    flashLOG connectionLOG;
    flashLOG disconnectionLOG;

    // Return a dynamically allocated string with the concatenation
    // of `a' and `b'.
    const char *str_concat(const char *a, const char *b)
    {
        char *s = new char[strlen(a) + strlen(b) + 1];
        strcpy(s, a);
        strcat(s, b);
        return s;
    }

public:
    IPmonitoring(const char *IP, const char *nick)
        : _IP(IP), _nick(nick),
        connectionLOG_filename(str_concat(nick, "_connlog.txt")),
        disconnectionLOG_filename(str_concat(nick, "_disconnlog.txt")),
        connectionLOG(connectionLOG_filename),
        disconnectionLOG(disconnectionLOG_filename)
    {}

    ~IPmonitoring(){
        delete[] connectionLOG_filename;
        delete[] disconnectionLOG_filename;
    }
};

Note the destructor, which is needed to avoid memory leaks, unless all
the instances of the class are statically allocated (which would be good
to avoid memory fragmentation). You may want to implement a copy
constructor and a copy assignment operator, as per the rule of
three.

48730: <p>I'm building a monitoring IP class, <code>IPmonitoring</code>, that using an SPIFFS class that I wrote, <code>flashLOG</code>. Inside <code>IPmonitoring</code> I have 2 instances of <code>flashLOG</code> (code below).</p>
<p>My sketch have several instances of <code>IPmonitoring</code> for several servicesI wish to monitor. I Wish that <code>connectionLOG</code> and <code>disconnectionLOG</code> have unique and automated names.</p>
<p>For example if I'm monitoring a service called <code>MQTT</code> its connect and disconnect log will be <code>MQTT_discolog.txt</code> and <code>MQTT_conlog.txt</code>. In my code below, <code>filename1</code> and <code> filename2</code> are consts.</p>
<pre><code>class IPmonitoring
{
private:
        char *_IP;
        char *_nick;

        flashLOG connectionLOG;
        flashLOG disconnectionLOG;

public:
        IPmonitoring(char *IP, char *nick, char *filename1 = &quot;/conlog.txt&quot;, char *filename2 = &quot;/disconlog.txt&quot;)
            : connectionLOG(filename1), disconnectionLOG(filename2)
        {
                _IP = IP;
                _nick = nick;
        }
</code></pre>
<p><strong>EDIT1 - example how to use class</strong></p>
<p>my goal is that <code>filename1</code> for example will be <code>MQTTbroker_connlog.txt</code> meaning a combination of <code>_nick</code> and a suffix,</p>
<pre><code>IPmonitoring MQTT_service(&quot;192.168.3.200&quot;,&quot;MQTTbroker&quot;);

void setup()
{
MQTT_service.start();
}

void loop()
{
MQTT_service.loop();
}
</code></pre>
 37622: <p>You have three options for the file names and generally.</p>
<ol>
<li>constant string a.k.a. string literal</li>
<li>string buffer global or on stack with scope valid while the string is used</li>
<li>dynamically allocated string on heap</li>
</ol>
<p>with 2) and 3) you can then build a string with C str or sprintf functions</p>
<p>option 3) is alright on MCU if you create these file names only at startup, not if you create them repeatedly as the sketch is running</p>
<p>If you choose option 3) you can build the strings in the constructor of IPmonitoring class, but you can't build the string in the member initialization part of the constructor. You have to add setters to <code>flashLOG</code> class and after building the strings for file names set them to the <code>flashLOG</code> instance with the setters.</p>
 7508: <p>Judging from your example usage, you want the filenames to be built by
the <code>IPmonitoring</code> constructor. However, since that class cannot know in
advance how much space is needed for the file names, you are left with
two choices:</p>
<ol>
<li><p>Let those file names be data members: arrays of <code>char</code> of some fixed
size. This will impose a limit on the maximum file name length.</p>
</li>
<li><p>Allocate the arrays dynamically at construction time.</p>
</li>
</ol>
<p>Here is a tentative implementation of the second approach:</p>
<pre class="lang-cpp prettyprint-override"><code>class IPmonitoring
{
private:
    const char *_IP;
    const char *_nick;
    const char *connectionLOG_filename;
    const char *disconnectionLOG_filename;
    flashLOG connectionLOG;
    flashLOG disconnectionLOG;

    // Return a dynamically allocated string with the concatenation
    // of `a' and `b'.
    const char *str_concat(const char *a, const char *b)
    {
        char *s = new char[strlen(a) + strlen(b) + 1];
        strcpy(s, a);
        strcat(s, b);
        return s;
    }

public:
    IPmonitoring(const char *IP, const char *nick)
        : _IP(IP), _nick(nick),
        connectionLOG_filename(str_concat(nick, &quot;_connlog.txt&quot;)),
        disconnectionLOG_filename(str_concat(nick, &quot;_disconnlog.txt&quot;)),
        connectionLOG(connectionLOG_filename),
        disconnectionLOG(disconnectionLOG_filename)
    {}

    ~IPmonitoring(){
        delete[] connectionLOG_filename;
        delete[] disconnectionLOG_filename;
    }
};
</code></pre>
<p>Note the destructor, which is needed to avoid memory leaks, unless all
the instances of the class are statically allocated (which would be good
to avoid memory fragmentation). You may want to implement a copy
constructor and a copy assignment operator, as per the <a href="https://en.wikipedia.org/wiki/Rule_of_three_(C%2B%2B_programming)" rel="nofollow noreferrer">rule of
three</a>.</p>
