|
Are you talking about a std::vector and a std::list ?
Don't think there is a direct conversion, you will need to copy from one to the other.
This signature was proudly tested on animals.
|
|
|
|
|
Yes : std::vector to std::list
What is the best method to copy the data? Can you give an example?
Thanks.
|
|
|
|
|
It's not MFC, but something like:
vector<int> vec;
vector<int>::iterator it;
list<int> l;
for (it = vec.begin(); it != vec.end(); it++)
l.push_back(*it);
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
I forget to mention it's two different data types see code below:
std::list<rdlresource*> TempRes;
TempRes.clear;
std::vector<rdltemporaryresource*>::iterator it;
for (it = TempResList.begin(); it != TempResList.end(); it++)
TempRes.push_back(*it);
Thanks the help on this.
|
|
|
|
|
Well I guess it did not compile fully earlier, I am still getting the compiler error message below when I tried to copied the data from a vector to a list.
ompiling...
FSSCHED.CPP
c:\program files\ilps\code\fstool\fssched.cpp(1165) : error C2664: 'push_back' : cannot convert parameter 1 from 'class RDLTemporaryResource *' to 'class RDLResource *const & '
Reason: cannot convert from 'class RDLTemporaryResource *' to 'class RDLResource *const '
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Error executing cl.exe.
fstool.dll - 1 error(s), 0 warning(s)
|
|
|
|
|
That's because your list is for RDLResource* objects while your iterator for that list is for RDLTemporaryResource* objects.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Right. So I am having problems transferring the data from the vector to the list.
How do I work around doing that in my case? I tied casting, it compiled but the application crashes at runtime.
Thanks.
|
|
|
|
|
Anderson Jogie wrote: How do I work around doing that in my case?
That's impossible to tell since I know nothing of either of those two classes. For example, how would you copy a vector of Automobile objects to a list of Animal objects?
Anderson Jogie wrote: I tied casting, it compiled but the application crashes at runtime.
That would not work unless the two classes had a "is a" relationship.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
DavidCrow wrote: That would not work unless the two classes had a "is a" relationship.
Reading that it occurred to me that a more casual (possibly less informed) reader might look at that, pause, and then have their head explode.
|
|
|
|
|
I agree.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
I'm not an STL expert, but after a quick google (bing did not give valid answers in the first few pages), here are a couple of solutions (adapt to your particular situation)
std::copy (v.begin (), v.end (), std::back_inserter (l))
or
std::list<int> l(v.begin(), v.end());
or ...
This signature was proudly tested on animals.
|
|
|
|
|
So you binged it, but it bonged out?
|
|
|
|
|
Just so you know, std::vector and std::list have nothing to do with MFC. They are part of STL or Standard Template Library and are cross platform.
|
|
|
|
|
Hello,
I am porting a Dialog based application that I used Lcc-Win32 to develop over to Visual C++.
How to I get the handle of my Dialog box?
Thanks in advance for your help.
|
|
|
|
|
jonsey29847 wrote: How to I get the handle of my Dialog box?
For what purpose?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
That question confuses me. What am I missing Dave? Just curious.
|
|
|
|
|
led mike wrote: That question confuses me.
Mine or the OP's?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
|
So I can use existing code in an application that I developed using Win32 APIs. i.e.SendMessage(HWND, ID, wparam, lparam)
MFC "Hides" this from me.
However, if I am taking off in wrong direction I would appreciate some guidance here.
Thanks
|
|
|
|
|
If you wanted to send a message to some edit control, you could use:
m_edit.SendMessage(WM_GETTEXTLENGTH, 0, 0); or
::SendMessage(m_edit.GetSafeHwnd(), WM_GETTEXTLENGTH, 0, 0); or
m_edit.GetWindowTextLength();
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
You have struck upon one of the problems I have using MFC.
What does m_edit mean and where can I find a list of all the m_whatever?
Thanks
|
|
|
|
|
jonsey29847 wrote: What does m_edit mean and where can I find a list of all the m_whatever?
It's just an arbitrary name I chose for that code snippet. You may call it whatever you wish.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Is it the name I assign using the class wizard?
|
|
|
|
|
Yes.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Wow!
I can't wait to try it.
I just love this website!
Thanks.
|
|
|
|