I haven't programmed in C++ since before .Net -- for Windows I use C# and .Net now.
I have a C# .Net DLL that I call from other C# programs with no problems. But I have a customer who wants to call it from C++ so I'm writing a practice app to see how it's done. NB this is C++/CLI ie, it's a managed, CLI-CIL-CLR app.
In my C# program I add my DLL as a reference then in my code I have a using statement and then instantiate it . . .
using ScannerBeam;
. . .
CScannerBeam SB = new CScannerBeam();
. . . works a treat, no problems. But in C++ I also add the DLL as a reference and do a
using namespace ScannerBeam;
. . .
CScannerBeam SB = gcnew CScannerBeam();
...and I get an error . . .
Error 1 error C3673: 'ScannerBeam::CScannerBeam' : class does not have a copy-constructor
Why does it need a copy constructor when C# doesn't? Does it need a deep copy or just a shallow one? Any other gotchas I need to know calling a C# DLL from (managed/CLI/CLR) C++?
引用类需要refptr,CScannerBeam ^表示C ++-CLI中的ref_ptr。
gcnew
evaluates to a tracking handle, of type CScannerBeam^
Your code is not much different from:
std::string s = new std::string();
which is also an error, the right side is a pointer and the left side isn't.
Just like native C++, use either
CScannerBeam SB; // creates an object with stack semantics
// it will be disposed at end the of the scope
func(sb.member);
or
CScannerBeam^ pSB = gcnew ScannerBeam(); // get handle to object on managed heap
// it has dynamic lifetime and will live as
// long as the .NET garbage collector can reach it
func(pSB->member);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.