Reputation: 73
I got a little problem with my C++/CLI progamm.
I got a few Char
arrays wo work without problems.
Header1:
ref class _CGuid{
static const int CIDGR=37;
public:
array<Char>^ cGuid;
array<Char>^ cUuid;
}
Cpp1 -> contruktor:
cGuid = gcnew array<Char>(CIDGR);
some function:
_CGuid::Type(String^ tmpname,String^ tmpid)
{
pcName=tmpname;
cUuid=tmpid->ToCharArray();
}
So this Works Perfectly fine for me without errors. How ever This doesn’t work:
Other Header:
ref class CStorage{
public:
array<String^>^ names;
array<Char>^ mac;
Other contruktor
names = gcnew array<String^>(100);
mac = gcnew array<Char>(100);
some function 2:
names[k]=tname;
mac[k]=tmac->ToCharArray(); <-------- Error Line
k++;
This line gets the error:
error C2440: '=' : cannot convert from
cli::array<Type> ^
towchar_t
with [ Type=wchar_t ]
There is no context in which this conversion is possible
So I really don´t know whats the problem here.
Upvotes: 0
Views: 1683
Reputation: 8469
here you copy a CLI array coming from the "ToCharArray" in 1 wchar_t of the Mac array!
mac[k]=tmac->ToCharArray(); <-------- Error Line
as you want an array of Mac Address you must allocate it with
mac = gcnew array<array<Char> >(100);
so now you can affect mac[k]
Upvotes: 0
Reputation: 545588
The error says it all, actually. ToCharArray
returns an array<Char>
, which you try to assign to a single Char
(= wchar_t
) when accessing mac[k]
.
Did you maybe mean to assign to mac
instead?
mac = tmac->ToCharArray();
If so, then this line is redundant:
mac = gcnew array<Char>(100);
Here you allocate memory for mac
which you later throw away when you re-assign mac
.
Upvotes: 1