c# - 为什么我的 C++ 代码看不到这个 C# 类成员?

标签 c# c++

我在 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/

相关文章:

c++ - 多读/单写类的线程安全

c++ - C++ 凯撒密码程序

c++ - 无法构建 lldb - 'atomic' 文件未找到

c++ - 为什么 visual studio 需要静态库 (.lib) 来进行动态链接?

c# - Parallel.ForEach 花费的时间比预期的多

c# - 使用 System.Web.Routing 时遇到的问题

c# - FileReader.readAsBinaryString 是否返回二进制或基于 ASCII 的字符集?

c++ - 重载 + 运算符时出现段错误

c# - 使用.NET 将多个代码文件编译成程序集?

c# - 在执行时更改 Gecko Webbrowser 中的代理设置?