I am a C programmer. I am working on a C++ code and translating it into C.
I got stuck in a point where I do not understand what is going on.
I would kindly ask if you would mine help me to understand these problems.

I have three problems:

1)There are two arrays with different length:

vector<double> D;
double temp[5];

//and then: 

D.resize(3, temp);

Does the programmer wants to copy temp[0], temp[1], and temp[2] into D[0], D[1], and D[2] ?

2)There is a two dimensional array

vector<vector<double> > F;

it is initialized like this:

F.resize(3, temp);

Since temp[5] is a one dimensional array, is it possible to copy it into a two dimensional array?

Finally array F which is a two dimensional array is passed as a one dimensional array into a function like this:

//declaration of function
void  do(vector<double> & F);


    // now F which is sopposed to be a two dimensional array is used like
for(int I; i<3; i++)  do(F[i]); // !!!!!!!!!!!!!


In C it is not possible as far as my knowledge. Is this possible in C++?

Thanks in advance for your kind help.

Edited by mike_2000_17: Fixed formatting

6 Years
Discussion Span
Last Post by Narue

>D.resize(3, temp);
Well that's wrong, and it shouldn't even compile. temp is an array of double and that particular overload of resize takes a value of type T (that the vector was declared with). Since T is double, it's a type mismatch.

>F.resize(3, temp);
This is equally wrong for the same reason. vector<double> isn't compatible with an array of double.

>void do(vector<double> & F);
Now I'm sure that you're paraphrasing rather than posting actual code. do is a freaking keyword in C++!

Your questions can't be properly answered until you give us something valid to work with. You can do what you're asking in C++ (and in C), but not that way.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.