[SOLVED] Result class as a member variable

Hi all,

Why can't use the Result class as a member variable in my class?

When I have :

.h file

class JUCE_API AppMainConfig
{
public:
    
    Result App_MainConfigStatus;
   

   static AppMainConfig& getInstance();

...e.t.c.


private:

AppMainConfig()

...e.t.c.

}

 

.cpp file


AppMainConfig::AppMainConfig()
{}

 

 I get the error  "error C2248: 'juce::Result::Result' : cannot access private member declared in class 'juce::Result' , which is marked on the class constructor definition.

I guess it's something simple but, after several hours on the issue,  I could not see it ...

Any idea?

PS. : As it shown my class is a singeton one.
 

Edit :  I realize the real reason of the error.
What I'm asking is : is there a way to use the Result class as a member inside an other class ?

 

Why have you made your AppMainConfig constructor private?

Result is designed to be a type returned by value to notify about the result of a function call. So you would create an object of this type using static functions Result::ok() or Result::fail (string), inside that function before returning it. It's not meant to be used for anything else - like having it as a class member.

To enforce that, the default constructor of Result is private, which is why your code doesn't compile.

Technically speaking, you could have a Result as a class member by initialising it in your class constructor's initialiser list, like this:

class Foo
{
public:

    Foo () 
       : result (Result::ok()) 
    {
         // ...
    }

private:

    Result result;
};

 

but I would advise against this as the class is not meant to be used this way.

Why have you made your AppMainConfig constructor private?

According to Singleton pattern.

Ok.  The Result class constructor is private too. 

 

 I would advise against this as the class is not meant to be used this way.

Just I realized it !

Thanks for the attention.   

 

It also means it can't be used in this handy way, unless I'm missing some obvious trick?  I probably am...


    Result r;

    if (type == removeWorkingCopy)
        r = workingCopy.renameTo (nextVersion);
    else
        r = workingCopy.copyTo(nextVersion); 

// followed by some common error handling code. 

{EDIT}  I was: 



Result r = Result::ok();  // works. 

if ...