[英]Why can't my C++ code see this C# class member?
I have several custom classes in a C# project that I then reference in a C++ project. 我在C#项目中有几个自定义类,然后我在C ++项目中引用它。 The C# code looks something like this C#代码看起来像这样
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. 然后从C ++我试图访问AllOptions的各个部分,但并非所有部分都通过。
//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". 算法说“Class AllOptions :: AlgorithmOptions没有成员算法”。 Why can't the C++ code see this particular C# member? 为什么C ++代码不能看到这个特定的C#成员?
EDIT My question was tagged as a possible duplicate to this Default access modifier in C# question. 编辑我的问题被标记为C#问题中此默认访问修饰符的可能重复。 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. 如果我想错了,请再次标记,我会改变它。
AlgorithmOptions.algorithms
is a private member. AlgorithmOptions.algorithms
是一个私有成员。 Only the containing class can access its private members. 只有包含类才能访问其私有成员。 In contrast, DatabaseOptions.databaseSources
is a public member, and you can access it from anywhere. 相比之下, DatabaseOptions.databaseSources
是一个公共成员,您可以从任何地方访问它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.