我在 C# 项目中有几个自定义类,然后在 C++ 项目中引用它们。 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; }
}
}
然后我试图从 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
算法说“类 AllOptions::AlgorithmOptions 没有成员算法”。为什么 C++ 代码看不到这个特定的 C# 成员?
编辑 我的问题被标记为可能与此 Default access modifier in C# 重复问题。然而,我相信这些是恰好导致相同答案的不同问题。如果我的想法错了,请重新标记它,我会更改它。
最佳答案
AlgorithmOptions.algorithms
是私有(private)成员。只有包含类才能访问其私有(private)成员。相反,DatabaseOptions.databaseSources
是一个公共(public)成员,您可以从任何地方访问它。
关于c# - 为什么我的 C++ 代码看不到这个 C# 类成员?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40383878/