【发布时间】:2016-11-02 15:32:40
【问题描述】:
我在 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
算法说“Class AllOptions::AlgorithmOptions 没有成员算法”。为什么 C++ 代码看不到这个特定的 C# 成员?
编辑我的问题被标记为可能与此Default access modifier in C# 问题重复。但是,我相信这些是碰巧导致相同答案的不同问题。如果我的想法有误,请重新标记,我会更改它。
【问题讨论】:
-
也许你在某个地方有错字。 C# 和 C++ 代码中的
databaseSrouces和databaseSources确实不匹配。 -
@NathanOliver,不幸的是,这只是我在这里打字不好,在代码中所有数据类型都匹配
-
能否请您使用正确的标签。您同时拥有
c#和c++。 -
@AndrewTruckle 这不是一个包含两者的问题吗?
-
糟糕——我看错了第一句话——你使用了两种语言。我坏了!