B
Baloff
Hello
could somebody please tell me what is wrong with my solution to the
following exercise?
many thanks
Define an array of int. Take the starting address of that array and
use static_cast to convert it into an void*. Write a function that
takes a void*, a number (indicating a number of bytes), and a value
(indicating the value to which each byte should be set) as arguments.
The function should set each byte in the specified range to the
specified value. Try out the function on your array of int.
I am not sure why I am getting this error
******************************error******************************
main.cpp: In function `void ini(void*, int, int)':
main.cpp:5: error: parse error before `;' token
main.cpp: In function `int main()':
main.cpp:16: error: parse error before `;' token
make: *** [main.o] Error 1
make: Target `proj1' not remade because of errors.
******************************code******************************
#include <iostream>
using namespace std;
void ini(void* vp, int byte, int val){
int* ia = static_cast<int*> vp;
for(int i=0; i<byte; ++i){
ia = val;
cout << ia << "\n";
}
}
int main(){
int a[5] = {};
void* vp = static_cast<void*> a;
ini(vp, 5, 1);
}
could somebody please tell me what is wrong with my solution to the
following exercise?
many thanks
Define an array of int. Take the starting address of that array and
use static_cast to convert it into an void*. Write a function that
takes a void*, a number (indicating a number of bytes), and a value
(indicating the value to which each byte should be set) as arguments.
The function should set each byte in the specified range to the
specified value. Try out the function on your array of int.
I am not sure why I am getting this error
******************************error******************************
main.cpp: In function `void ini(void*, int, int)':
main.cpp:5: error: parse error before `;' token
main.cpp: In function `int main()':
main.cpp:16: error: parse error before `;' token
make: *** [main.o] Error 1
make: Target `proj1' not remade because of errors.
******************************code******************************
#include <iostream>
using namespace std;
void ini(void* vp, int byte, int val){
int* ia = static_cast<int*> vp;
for(int i=0; i<byte; ++i){
ia = val;
cout << ia << "\n";
}
}
int main(){
int a[5] = {};
void* vp = static_cast<void*> a;
ini(vp, 5, 1);
}