duplicate an array from the reference

L

LeonLeon

Hi Experts,

I am a newbie in C++ and have a entry-level question about the array
duplication.
There is a array dphi[][], from which a new array dphi_fwd[][] would
be copies,
I tried without success to do it with pointer, this is my first poster
I know there
are many talents here, so anybody could help me out? Thanks in
advance.

Bests,
Liang


*************The part code ********************

AutoPtr<FEBase> fe (FEBase::build(dim, fe_type));
const std::vector<std::vector<RealGradient> >& dphi = fe->get_dphi();
// dphi is a 2d array going like dphi[j](2);
// push forward dphi[][]
std::vector<std::vector<RealGradient> > *dphi_fwd = &dphi; // error
// dphi_fwd array has the same structure as dphi, but occupies
different memory and
can be updated later.
// how to define the dphi_fwd?
 
V

Victor Bazarov

I am a newbie in C++ and have a entry-level question about the array
duplication.
There is a array dphi[][], from which a new array dphi_fwd[][] would
be copies,
I tried without success to do it with pointer, this is my first poster
I know there
are many talents here, so anybody could help me out? Thanks in
advance.

Bests,
Liang


*************The part code ********************

AutoPtr<FEBase> fe (FEBase::build(dim, fe_type));
const std::vector<std::vector<RealGradient> >& dphi = fe->get_dphi();
// dphi is a 2d array going like dphi[j](2);
// push forward dphi[][]
std::vector<std::vector<RealGradient> > *dphi_fwd =&dphi; // error
// dphi_fwd array has the same structure as dphi, but occupies
different memory and
can be updated later.
// how to define the dphi_fwd?


http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.8

http://www.parashift.com/c++-faq-lite/

http://www.catb.org/~esr/faqs/smart-questions.html

V
 
A

Alf P. Steinbach

* LeonLeon, on 28.05.2010 21:36:
Hi Experts,

I am a newbie in C++ and have a entry-level question about the array
duplication.
There is a array dphi[][], from which a new array dphi_fwd[][] would
be copies,
I tried without success to do it with pointer, this is my first poster
I know there
are many talents here, so anybody could help me out? Thanks in
advance.

Bests,
Liang


*************The part code ********************

AutoPtr<FEBase> fe (FEBase::build(dim, fe_type));
const std::vector<std::vector<RealGradient> >& dphi = fe->get_dphi();
// dphi is a 2d array going like dphi[j](2);
// push forward dphi[][]
std::vector<std::vector<RealGradient> > *dphi_fwd =&dphi; // error
// dphi_fwd array has the same structure as dphi, but occupies
different memory and
can be updated later.
// how to define the dphi_fwd?


Just remove the * and & in the line with "error". However, there shouldn't be
any error, as far as I can see. It's just that a pointer is a pointer, not a copy.


Cheers & hth.,

- Alf
 
L

LeonLeon

Just remove the * and &in the line with "error". However, there shouldn't be
any error, as far as I can see. It's just that a pointer is a pointer,not a copy.

Ohh, that works well, I appreciate that!

Bests,

Liang
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,062
Latest member
OrderKetozenseACV

Latest Threads

Top