Wandbox
SettingsLog
SettingsLog
Language
GitHubLogin
Ran/Viewed Log

Viewed less than a minute ago

YCurHjpffE0LVlMc

C++ gcc 12.1.0

Created at 2 minutes ago

Created by anonymous

Author

anonymous

2 minutes ago

Language

C++

Compiler

gcc 12.1.0

Options
Warnings
Optimization
Don't Use Boost
C++11
-pedantic
セオライド・テクノロジー㈱株式会社フィックスターズ
Siv3D

Author

anonymous

2 minutes ago

›
⌄
⌄
⌄
⌄
⌄
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <iostream>

// * PLAYING WITH POINTERS!!!

using namespace std;

void example(string *pizzas, int i_row, int i_column);

int main(){
int row=2,column=12;
string pizzas[row][column] {{"pizza0","pizza1","pizza2","pizza3","pizza4"},
{"pizza5","pizza6","pizza7","pizza8","pizza9"}};
int i_row = sizeof(pizzas)/sizeof(pizzas[0]),i_column = sizeof(pizzas[0])/sizeof(pizzas[0][0]);
//string * sample = &pizzas[0];
//const int size{sizeof(pizzas)/sizeof(pizzas[0])};
// ? why i get *cannot convert ‘std::__cxx11::string (*)[column] {aka std::__cxx11::basic_string<char>
// ? (*)[column]}’ to ‘std::__cxx11::string* {aka std::__cxx11::basic_string<char>*}’ for argument ‘1’ to ‘void example(std::__cxx11::string*, int*, int*)’*
example(pizzas, i_row, i_column);
/*
cout<<*sample<<'\n';

sample = &pizzas[4];

cout<<*sample<<'\n';
*/
}
void example(string *pizzas, int i_row, int i_column){
// ? also i get error forbids comparison between pointer and integer
//row
for (size_t i = 0; i != i_row; i++){
//colum
for (size_t j = 0; j != i_column; j++)
cout<< pizzas[i][j] << ' ';
cout<<endl;
}
}
$ g++ prog.cc -Wall -Wextra -I/opt/wandbox/boost-1.79.0-gcc-12.1.0/include -std=gnu++2b
prog.cc: In function 'int main()':
prog.cc:11:12: warning: ISO C++ forbids variable length array 'pizzas' [-Wvla]
   11 |     string pizzas[row][column] {{"pizza0","pizza1","pizza2","pizza3","pizza4"},
      |            ^~~~~~
prog.cc:11:12: warning: ISO C++ forbids variable length array 'pizzas' [-Wvla]
prog.cc:18:13: error: cannot convert 'std::string (*)[column]' {aka 'std::__cxx11::basic_string<char> (*)[column]'} to 'std::string*' {aka 'std::__cxx11::basic_string<char>*'}
   18 |     example(pizzas, i_row, i_column);
      |             ^~~~~~
      |             |
      |             std::string (*)[column] {aka std::__cxx11::basic_string<char> (*)[column]}
prog.cc:7:22: note:   initializing argument 1 of 'void example(std::string*, int, int)'
    7 | void example(string *pizzas, int i_row, int i_column);
      |              ~~~~~~~~^~~~~~
prog.cc: In function 'void example(std::string*, int, int)':
prog.cc:30:26: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   30 |     for (size_t i = 0; i != i_row; i++){
      |                        ~~^~~~~~~~
prog.cc:32:30: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   32 |         for (size_t j = 0; j != i_column; j++)
      |                            ~~^~~~~~~~~~~
Exit Code:
1
セオライド・テクノロジー㈱株式会社フィックスターズ
Siv3D