【发布时间】:2014-12-31 00:32:10
【问题描述】:
我有一个非常简单的 C++ 类库,其中包含两种帐户类型,称为 Checking 和 Savings。我已经构建了这个项目并将其编译成一个名为 Accounts 的 .dll。我在我的 C# 控制台应用程序中引用了 Accounts.dll。无济于事,我尝试分别从 Savings 和 Checking 类中使用静态类 deposit 和 withdraw .我没有在对象浏览器或 Intellisense 中看到这些函数,并且当我尝试访问这些函数时无法构建它,否则当我注释掉对 mySavings.deposit 的调用时我能够构建和运行(arg1,arg2)...
知道我在这里做错了什么吗?我经常从其他项目和第三方引用 .dll,但这是第一次在 C# 项目中引用 C++ .dll。
C++ 类库
#pragma once
using namespace System;
namespace Accounts {
public ref class Savings
{
public:
unsigned accountNumber;
double balance;
static double deposit(Savings s, double amount)
{
s.balance += amount;
return s.balance;
}
};
public ref class Checking
{
public:
unsigned accountNumber;
double balance;
static double withdraw(Checking c, double amount)
{
c.balance -= amount;
return c.balance;
}
};
}
引用上面编译的动态链接库的C#控制台应用程序
using Accounts;
class Program
{
static void Main(string[] args)
{
Savings mySavings = new Savings(); // works but object is empty
mySavings.deposit(mySavings, 100); // still breaks
}
}
我收到以下错误:“Accounts.Savings”不包含“deposit”的定义,并且找不到接受“Accounts.Savings”类型的第一个参数的扩展方法“deposit”(您是否缺少使用指令还是程序集引用?)
任何帮助将不胜感激。
【问题讨论】: