|
I think I had something similar which didn't work;
CObArray array1;
CObArray array2;
.....
array2.Add(&array1);
......
CObArray RetrieveArray;
RetrieveArray.Copy( *(CObArray *)array2.GetAt(2));
pre>
|
|
|
|
|
How did it fail?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
For instance,
for(int i=0; i< 3; i++){
if(i==0)
array2.add(&a);
if(i==1)
array2.add(&b)
if(i==2)
array2.add(&c)
}
RetrieveArray.Copy( *(CObArray*)array2.GetAt(0)); RetrieveArray.Copy( *(CObArray*)array2.GetAt(1));
it seems to always come back with the last array no matter what I do! arra2.GetSize() = 3, which is right.
|
|
|
|
|
I did a very simple experiment and it worked fine for me:
CString as("as"), bs("bs"), cs("cs");
CObArray array2, a, b, c;
a.Add((CObject*)&as);
b.Add((CObject*)&bs);
c.Add((CObject*)&cs);
for(int i=0; i< 3; i++)
{
if(i==0)
array2.Add(&a);
if(i==1)
array2.Add(&b);
if(i==2)
array2.Add(&c);
}
CObArray aRetrieveArray, bRetrieveArray, cRetrieveArray;
aRetrieveArray.Copy( *(CObArray*)array2.GetAt(0));
bRetrieveArray.Copy( *(CObArray*)array2.GetAt(1));
cRetrieveArray.Copy( *(CObArray*)array2.GetAt(2));
CString *astr = (CString *)aRetrieveArray.GetAt(0);
CString *bstr = (CString *)bRetrieveArray.GetAt(0);
CString *cstr = (CString *)cRetrieveArray.GetAt(0);
AfxMessageBox((*astr) + _T("\n") + (*bstr) + _T("\n") + (*cstr));
Maybe i am not getting your point.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
I appreciate taking yout time. I am testing your sample code and comparing it to my code to realize the differences. The only thing that stands out is I have data of Type Class objects to fill out the arrays, as opposed to the Strings you put in, but this should be irrelevant.
I will let you know in few.
Thanks
|
|
|
|
|
Ok, I swapped your code a bit to get it more like what I need it to do:
CString as("as"), bs("bs"), cs("cs");
CObArray array2, a, b, c;
for(int i=0; i< 3; i++){
if(i==0){
a.Add((CObject*)&as);
array2.Add(&a);
}
if(i==1){
a.Add((CObject*)&bs);
array2.Add(&a);
}
if(i==2){
a.Add((CObject*)&cs);
array2.Add(&a);
}
}
CObArray aRetrieveArray, bRetrieveArray, cRetrieveArray;
aRetrieveArray.Copy( *(CObArray*)array2.GetAt(0));
bRetrieveArray.Copy( *(CObArray*)array2.GetAt(1));
cRetrieveArray.Copy( *(CObArray*)array2.GetAt(2));
CString *astr = (CString *)aRetrieveArray.GetAt(0);
CString *bstr = (CString *)bRetrieveArray.GetAt(0);
CString *cstr = (CString *)cRetrieveArray.GetAt(0);
AfxMessageBox((*astr) + _T("\n") + (*bstr) + _T("\n") + (*cstr));
What I am trying to say is, When I am doing array2.Add(&a), array a could be different everytime...but When I do the retrieveArray, it comes back with the last array a...in this case aRetrieveArray, bRetrieveArray, bRetrieveArray all = "as"... Not sure what am doing wrong
|
|
|
|
|
Here:
Software2007 wrote: if(i==0){
a.Add((CObject*)&as);
array2.Add(&a);
}
you add as to the array a and then add a to array2, right? So the first item of a is as and the first item of array2 is a.
Now here:
Software2007 wrote: if(i==1){
a.Add((CObject*)&bs);
array2.Add(&a);
}
you add bs to the array a, so the first item of a is as and the seond item of a isbs, then you add a again to array2 so both the first and second item of array2 is a, right?
Here:
Software2007 wrote: if(i==2){
a.Add((CObject*)&cs);
array2.Add(&a);
}
you add cs to the array a, so the first item of a is as, the second item is bs and the third item is now cs. Then you add a again to array2, so now array2 has 3 items and all 3 items is a, right?
When you do this:
Software2007 wrote: aRetrieveArray.Copy( *(CObArray*)array2.GetAt(0));
bRetrieveArray.Copy( *(CObArray*)array2.GetAt(1));
cRetrieveArray.Copy( *(CObArray*)array2.GetAt(2));
you actually copying the array a into aRetrieveArray, bRetrieveArray and cRetrieveArray, since all 3 items of array2 is a. Later here:
Software2007 wrote: CString *astr = (CString *)aRetrieveArray.GetAt(0);
CString *bstr = (CString *)bRetrieveArray.GetAt(0);
CString *cstr = (CString *)cRetrieveArray.GetAt(0);
, since all 3 arrays contain a copy of a you will put the first element of a, which is a pointer to as, into astr, bstr and cstr and then get the string in the message box "as\nas\nas".
Please note that CObjArray contains pointers to objects, not copies of objects, so if you add a pointer to a 3 times to the same array, it will contain 3 pointers to the original a, not 3 copies of a which then live separate lifes.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
Thanks of the explanation. But, not sure how I would be growing the same array (a) in this case and copying it over to array2...Or, there any other way to do this, may be some kind of a Stack?
|
|
|
|
|
I'm afraid i don't understand what you actually want to achieve...
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
All I want to do is this,
CobArray A = as
CobArray A = bs after an update of some type
CobArray A = cs after another update
I want to create an Array that holds the CobArray A every time it changes, so when I ask for the update that happened at #2 for example, I would get the array A = bs.
I am doing this to take snap shots of an array cuz I want to implement Undo and Redo logic, so I want to keep sanp shots of an array that I have so I can move forwards and backward in the list if you will.
modified on Friday, June 5, 2009 11:25 AM
|
|
|
|
|
You should then copy the original array and place the copy into your "undo-stack" array i guess...there are also smarter ways which are of course harder to implement that hold only the changes and not the whole array...
So to hold a snapshot of your original array you could do something like this (no success checking):
CObArray undo_array;
...
void AddToUndoArray(CObArray &array)
{
CObArray *CopyArray = new CObArray;
CopyArray->Copy(array);
undo_array.Add(CopyArray);
}
...
void GetFromUndoArray(CObArray &array, int index)
{
array.Copy(*undo_array.GetAt(index));
}
...
void DeleteUntoArray()
{
for (int i = 0, maxi = unto_array.GetCount(); i < maxi; i++)
delete undo_array.GetAt(i);
undo_array.RemoveAll();
}
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
I tried your Add method, and it worked like I wanted. I can go from there, I appreciate your help..Very good and insightful.
|
|
|
|
|
Great, i'm glad it worked out.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
hi. i have downloaded the complete zip file of CSmtp_v1_5 and i use Dev C++ 4.9.9.2 to compile the main file of this zip file. when i compile there is a message like this
[Linker error] undefined reference to `CSmtp::CSmtp()'
[Linker error] undefined reference to `CSmtp::SetSMTPServer(char const*, unsigned short)'
[Linker error] undefined reference to `CSmtp::AddRecipient(char const*, char const*)'
i am unable to compile this main.cpp file due tolinker error.please help me. how can i compile that main.cpp file?
ravi joshi
|
|
|
|
|
Why don't you ask in the article forum?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Good morning
I wrote a program to copy files and directories I must put the
of source and destination directory.
But now I want to make it my default copier program I want to
patch default windows copy dialog and replace it for my program.
Eg:When user makes right clic copy and right clic paste how can get
source and destination directory.
I currently read a small tutoriel but he use MFC to developpe shell copy
and i know nothing about MFC.
Can you help me please.
Thank you.
|
|
|
|
|
aurelcly wrote: Eg:When user makes right clic copy and right clic paste how can get source and destination directory.
This sounds like a shell extension. Read here for more.
"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 have vector whose values i cant read while debugging so i want to see that values in .txt file.so please anyone help.
Project Engineer
|
|
|
|
|
something like this:
#include <fstream.h>
vector<CString> myVector;
myVector.push_back("a string");
myVector.push_back("another string");
fstream file_op("c:\\vector.txt",ios::out);
for (myVector::iterator it = myVector.begin(); it != myVector.end(); it++)
file_op<< (*it);
file_op.close();
|
|
|
|
|
Another alternative, just because I like STL algorithms
#include <fstream>
#include <iterator>
#include <algorithm>
std::vector<std::string> myVector;
myVector.push_back("a string");
myVector.push_back("another string");
std::ofstream file_op("c:\\vector.txt");
std::copy(myVector.begin(), myVector.end(), std::ostream_iterator<std::string>(file_op, "\n"));
file_op.close();
The other question is - why can't you see the values of the vector - is there possibly some way round that?
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
IIRC, VC6 wouldn't show you the contents of a vector - well, maybe the first element. VS05 and 08 are much nicer about that.
|
|
|
|
|
VC6 Yeah, I don't go that far back any more I was going to suggest looking at the internal bits of the vector in the Immediate window - but that's a VS2003-only technique - VC6 didn't have an Immediate window did it? In VS2003, if you had a vector called a, you could type something like ? a._Myfirst[3] in the Immediate window and see the [3] element of the vector.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
had simulated a 3 d array as follows
typedef unsigned short byte;
nbands=layers;
j=x_length*y_length;
byte**data_1=new byte*[nbands];
data1[0]=new byte[nbands*j];
for(int i=1;i<nbands<++i)
{
data1[1]=data1[i-1]+j;
)
now consider the 3d equivalent array to be[layers][y_length][x_length]
//assume the data is stored in data_1
suppose i create a data_2
byte**data_2=new byte*[x_length];
data2[0]=new byte[nbands*j];
for(int i=1;i<x_length;++i)
{
data2[1]=data2[i-1]+(nbands*y_length);
)
how to i transfer the data frm data_1 to 2
my req dimension nw wud be [x_length][layers][y_length]as comp to the first one
ie if layers=64
and [y][x]=[256][241]or something
wat wud function convertdata_1to2 look like???
i express my eq 3d matrices[layers][y][x]
please do help
thanks in advance
modified on Friday, June 5, 2009 8:27 AM
|
|
|
|
|
Please change your title, as 'repost' is not welcomed here, I suppose.
roshinisachi wrote: byte**data_1=new byte*[nbands];
Three dimensions? I see two dimensions.
roshinisachi wrote: for(int i=1;i<nbands<++i)
{
data1[1]=data1[i-1]+j;
)< blockquote="">roshinisachi wrote: for(int i=1;i<x_length;++i)
{
data2[1]=data2[i-1]+(nbands*y_length);
)
how< blockquote="">
What is the purpose of the above code?
If you're interested in three dimensional arrays, you can just use them, can't you?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
sir
i'm working on some interconversion between file formats..which requires the current structure
please suggest me a solution
|
|
|
|