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);

main(){

    // 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.

>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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.