Re: Convert Objects from an Arraylists to Double?
Hi! Ben
I've looked closely at what you've written and tried to do what you've said
but I end up with more error messages. I'm kind of new to this managed C++
approach as you might have guessed. I have some experience with VS 6.0 and
have now started with VS2008. I can tell you that It's been a bit of a
cultural chock for me :-)
Here is the how the code look now:
////////////////////////////////////////////////////////////////////////////////////////////
using namespace System::Collections::Generic;
....
....
....
if(COpenFile::get_stmReader())
{
//!! EN ARRAYLIST MED R??TT ENTITETER !!
ArrayList^ lstTest = pForm1.get_LineX_StartValueArray();
//!! EN DOUBLE ARRAY MED R??TT STORLEK !!
array<double>^ dblArray = gcnew array<double>(
(int)CConvert::get_NumberOfItems() );
List<System::Double> ^ List1 = pForm1.get_LineX_StartValueArray();
List<System::Double> ^ List2 = pForm1.get_LineY_StartValueArray();
List<System::Double> ^ List3 = pForm1.get_LineX_EndValueArray();
List<System::Double> ^ List4 = pForm1.get_LineY_EndValueArray();
for( int i = 0; i < List1->Count; ++i )
{
g->DrawLine( System::Drawing::Pens::Red, List1[ i ], List2[ i ], List3[ i
], List4[ i ]);
}
}
////////////////////////////////////////////////////////////////////////////////////////////
Error message;
////////////////////////////////////////////////////////////////////////////////////////////
\DrawLine.cpp(38) : error C2440: 'initializing' : cannot convert from
'System::Collections::ArrayList ^' to 'System::Collections::Generic::List<T>
^'
1> with
1> [
1> T=double
1> ]
1> No user-defined-conversion operator available, or
1> Types pointed to are unrelated; conversion requires
reinterpret_cast, C-style cast or function-style cast
1>.\DrawLine.cpp(39) : error C2440: 'initializing' : cannot convert from
'System::Collections::ArrayList ^' to 'System::Collections::Generic::List<T>
^'
1> with
1> [
1> T=double
1> ]
1> No user-defined-conversion operator available, or
1> Types pointed to are unrelated; conversion requires
reinterpret_cast, C-style cast or function-style cast
////////////////////////////////////////////////////////////////////////////////////////////
Maybe it???s obvious to you when you see the error message above. I must admit
that I've come to a point where I???ve started to look at alternative
solutions, I'm sorry to say. Time is running out for ArrayList.
Regard
KC
"Ben Voigt [C++ MVP]" wrote:
I've tried this approach among others but no luck so far;
List< double > ^ list1 = pForm1.get_LineX_StartValueArray();
List< double > ^ list2 = pForm1.get_LineY_StartValueArray();
List< double > ^ list3 = pForm1.get_LineX_EndValueArray();
List< double > ^ list4 = pForm1.get_LineY_EndValueArray();
for( int i = 0; i < list1->Count; ++i )
{
g->DrawLine( System::Drawing::Pens::Red, list1[ i ], list2[ i ],
list3[
i ],
list4[ i ]);
}
Above code snippet generates a;
error C3699: '^' : cannot use this indirection on type 'std::list<_Ty>'
This one should have worked. Note that the error message mentions list,
small L. Do you have a typo in your code or a macro defining List to list
or some such? Maybe the compiler is just guessing at which class you meant.
Do you have "using namespace System::Collections::Generic;"? Otherwise you
can say "System::Collections::Generic::List<System::Double>^"
Don't use "using namespace std" in C++/CLI managed code, it's asking for
confusion. The number of times you want the standard library in a .NET
program is so small you can just explicitly say std::whatever.
I'm using VS 2008
Many thanks
Regards
//KC