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.

8
  • 1
    Maybe you have a typo somewhere. You do have mismatching databaseSrouces and databaseSources in the C# and C++ code respectively. Commented Nov 2, 2016 at 15:34
  • @NathanOliver, That unfortunately is just my poor typing on here, in code all the data types match up Commented Nov 2, 2016 at 15:36
  • Can you please use the right tag. You have both c# and c++. Commented Nov 2, 2016 at 15:38
  • @AndrewTruckle Is this not an issue containing both? Commented Nov 2, 2016 at 15:39
  • 1
    Oops - I misread the first sentence - you are using both languages. Me bad! Commented Nov 2, 2016 at 15:41

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I feel foolish, I had forgotten the standard protection level was private and that is indeed my error. Thank you for the quick reply

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.