I typed these code in Geany:
void copy_fct()
{
int v1[10] = {0,1,2,3,4,5,6,7,8,9};
int v2[10] = {0,0,0,0,0,0,0,0,0,0};
// to become a copy of v1
for(auto i=0; i!=10; ++i) // copy elements
v2[i]=v1[i];
// ...
}
while, when I compiled it, there was always a red wave line under "int v2[10]", I tried "int v2[] = {0,0,0,0,0,0,0,0,0,0};" "int v2[];" and "int v2[10] = {};", all the same, I tried declared v2 outside "copy_fct()", it was OK, but, if I do want to declare it inside "copy_fct()", is there a declaration here without descend the warning level (now is default "Wall")?
The whole code was:
#include <iostream>
using namespace std;
int main()
{
std::cout<<"Hello,World!\n";
}
bool accept3()
{
int tries = 1;
while(tries<4){
cout << "Do you want to proceed (y or n)?\n"; // write question
char answer = 0;
cin >> answer; // read answer
switch(answer){
case 'y':
return true;
case 'n':
return false;
default:
cout << "Sorry, I don't understand that.\n";
++tries; // increment
}
}
cout << "I'll take taht for a no.\n";
return false;
}
void copy_fct()
{
int v1[10] = {0,1,2,3,4,5,6,7,8,9};
int v2[10] = {0,0,0,0,0,0,0,0,0,0};
// to become a copy of v1
for(auto i=0; i!=10; ++i) // copy elements
v2[i]=v1[i];
// ...
}
0 Answers