Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Copy from CArray<sVector,sVector> to sVector *ArrayOfVectors

Posted on 2004-09-22
5
Medium Priority
?
301 Views
Last Modified: 2010-04-01
Hi,
I have an sVector struct:

typedef t_Vector
{
        double Xcoord,
        double Ycoord,
        double Zcoord
}
and:


CArray<sVector,sVector>              TempVectorsArray;

sVector                                        *ArrayOfVectors;

I need to copy all the element from TempVectorsArray to ArrayOfVectors, but each time
when i get into the copy  i need to copy the data from the TempVectorsArray into a
different place on the ArrayOfVectors,for example:

for(int base_index =0 ; base_index<100; base_index++)
{
     // I need to change this line to the correct form - copy from TempVectorsArray to    
     // ArrayOfVectors[base_index]
     ArrayOfVectors[base_index] = TempVectorsArray;   //now it's error of course
}


Thanks a lot:-)
0
Comment
Question by:dani333
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 

Author Comment

by:dani333
ID: 12127957
the correct struct is of course :

typedef t_Vector
{
        double Xcoord,
        double Ycoord,
        double Zcoord
}sVector;

sorry for the mistake.
0
 
LVL 22

Accepted Solution

by:
NovaDenizen earned 360 total points
ID: 12128146
Something more like this?

int base_index;
...calc base_index here...
int len = TempVectorsArray.length();
int i;
for(i = 0; i < len; i++) {
    ArrayOfVectors[base_index + i] = TempVectorsArray[i];
}

This copies all elements from TempVectorsArray into a subrange of ArrayOfVectors starting at index base_index.  Make sure that ArrayOfVectors is allocated to be big enough to contain all elements of TempVectorsArray.

0
 

Author Comment

by:dani333
ID: 12128287
yes,but do you have another way without looping all the elements in the array?
with pointers , address or something like that?
0
 

Author Comment

by:dani333
ID: 12128380
Maybe memcpy or ather way....
0
 
LVL 9

Expert Comment

by:jhshukla
ID: 12129238
i would not suggest memcpy unless you are sure that sVectors are laid out in contiguous chunk of memory.
0

Featured Post

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question