3

I have several custom classes in a C# project that I then reference in a C++ project. The C# code looks something like this

namespace AllOptions
{
    public class AllOptions {
        public AlgorithmOptions algOptions{ get; set; }
        public DatabaseOptions dataOptions{ get; set; }
    }

    public class AlgorithmOptions {
        List<Algorithm> algorithms { get; set; }

        public void SetDefaults(){
            this.algorithms.Clear();
        }
    }
    public class Algorithm {
        public bool AllowSalt { get; set; }
    }
    public class DatabaseOptions {
        public List<string> databaseSrouces { get; set; }
    }
}

And then from C++ I am trying to access the various parts of the AllOptions but not all of them are coming through.

//Is declared at the beginning
public: VerifyOptions::VerifyOptions Options;

//Then later on I try to access the database options and algorithm options
this->Options.databaseOptions->databaseSources = someStringList; //works fine

//This cannot find the algorithm list
this->Options.algorithmOptions->algorithms = someAlgorithmList; //does not work

The algorithms says "Class AllOptions::AlgorithmOptions has no member algorithms". Why can't the C++ code see this particular C# member?

EDIT My question was tagged as a possible duplicate to this Default access modifier in C# question. However I believe these to be different questions that happened to result in the same answer. If I am wrong in thinking that please tag it again and I will change it.

Community
  • 1
  • 1
WWZee
  • 494
  • 2
  • 8
  • 23

1 Answers1

7

AlgorithmOptions.algorithms is a private member. Only the containing class can access its private members. In contrast, DatabaseOptions.databaseSources is a public member, and you can access it from anywhere.

Luaan
  • 62,244
  • 7
  • 97
  • 116
  • I feel foolish, I had forgotten the standard protection level was private and that is indeed my error. Thank you for the quick reply – WWZee Nov 02 '16 at 15:39