这么写就是编译不过的:
- C/C++ code
public ref struct ABC{ SqlDataAdapter^ commodityInfoDA; DealSuite(int inInt) : commodityInfoDA("SELECT * FROM dbo.commodityInfo WHERE dbo.commodityInfo.commodityID=" + inInt.ToString() + ";", gcnew SqlConnection("Data Source=192.168.1.2\pitsou7;Initial Catalog=ATM_PITSOU7;Integrated Security=false;User ID=sa;Password=123456")) { }}
.
这么写编译就过了:
- C/C++ code
public ref struct ABC{ SqlDataAdapter^ commodityInfoDA; DealSuite(int inInt) { commodityInfoDA = gcnew SqlDataAdapter("SELECT * FROM dbo.commodityInfo WHERE dbo.commodityInfo.commodityID=" + inInt.ToString() + ";", gcnew SqlConnection("Data Source=192.168.1.2\pitsou7;Initial Catalog=ATM_PITSOU7;Integrated Security=false;User ID=sa;Password=123456")); }}
.
求解释.
------解决方案--------------------------------------------------------
当然了,CLI 不像 c++ 那样CObject obj就构造出一个对象来,而只是声明了一个nullptr指针而已。要构造一个对象,必须gcnew。
------解决方案--------------------------------------------------------
C++本来如此,这一点和cli有个屁关系
commodityInfoDA 要求一个sqldataadpater,你给他一个字符串,能对吗?
又没有转换函数
------解决方案--------------------------------------------------------
class A{
int a;
public:
A( int temp):a(temp)
{}
};
A* a1;
a1 = 10; ????////这句话对吗?