Essentially I have two header files, one called 'ACYDTypes.h' that contains the classes for the basic types of this system and the other called 'Settings.h' that contains function for general settings.

In the Settings.h file, there is a namespace called 'Ac_Type_Settings', and within that is a class called 'AcTypeSettings'. This contains changeable static variables of settings that will affect the classes in the 'ACYDTypes.h'. I have made all the classes in 'ACYDTypes.h' a friend of this class so that my system's basic types can directly access varible settings affecting them, rather than having to call a public function from the ACYDTypeSettings class (which also means that anyone else can call these functions and retrieve that data which is only intended for the basic types).

However the classes in 'ACYDTypes.h' bring up errors saying that they cannot access private members of the class that made it a friend.

Is it possible to get this working, or would I have to keep these settings in different files alongside the classes and code that relate to them?

I'm keeping these in seperate headers as 'Settings.h' will include settings for all over the system, and it's easier for the user to access these in one location.

This is 'Settings.h'

#pragma once

#include "ACYDTypes.h"

namespace Ac_Type_Settings
{
    #define ACYD_SETTINGS_ACTYPE_INTROUNDUP     0;
    #define ACYD_SETTINGS_ACTYPE_INTROUNDDOWN   1;

    class AcTypeSettings;

    class AcTypeSettings
    {
    private:

        static unsigned int _intRounding;

    public:

        static void SetIntRounding(unsigned int const setting)
        {
            _intRounding = setting;
        }

        static unsigned int GetIntRounding(void)
        {
            return _intRounding;
        }

        friend class Ac_Type::acBool;
        friend class Ac_Type::acChar;
        friend class Ac_Type::acDouble;
        friend class Ac_Type::acFloat;
        friend class Ac_Type::acInt;
        friend class Ac_Type::acLong;
        friend class Ac_Type::acShort;
        friend class Ac_Type::acString;

    };
}

and this is 'ACYDTypes.h'

#pragma once

#include "IACYD.h"
#include "Settings.h"

using namespace Interface_Ac_Type;

namespace Ac_Type
{
    class acInt;
    class acFloat;
    class acDouble;
    class asShort;
    class acLong;
    class acBool;
    class acChar;
    class acString;


    class acInt : IAcType , IAcTypeErrHelp
    {
    private:

        int _value;

    public:
        acInt()
        {
            _value = 0;
        }

        acInt(int const value)
        {
            _value = value;
        }

        acInt(float const value)
        {
            // Compare the static variable that we are friends of in the Type Settings.
            if (Ac_Type_Settings::AcTypeSettings::_intRounding == ACYD_SETTINGS_ACTYPE_INTROUNDDOWN)
            {
                // round down the float.
            }
            else
            {
                // round up the float.
            }
        }
};

By the way, I do not get the error of multiple #includes and depth problems. I've included the '#pragma one' to solve that

I didn't make it exactly specific.

The error is with the static variable '_intRounding' on line 40 of 'ACYDTypes.h'

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.