Salut,
Je suis en train de lire le livre "Thinking in c++ 2nd, Vol. 1" et j'ai de la difficulté à comprendre un exercice. Voici l'énoncé, ça explique tout:
Je ne comprend pas exactement ce qu'ils veulent que je fasse. Enfin, j'en suis arrivé à ceci pour le moment: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.
Je ne sais même pas si je suis dans le bonne direction... Ça doit être dû à ma compréhension de l'anglais
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 #include <iostream> using namespace std; void unefonction( void* pletableau, int nboctets, int valeur); int main() { int montableau[10]; int* p = montableau; void* pv = static_cast<void*>(p); unefonction( pv, sizeof(int), 10); } void unefonction( void* pletableau, int nboctets, int valeur) { // Aucune idée quoi faire ici. }
Quelqu'un peut me dire si je suis dans la bonne direction ou me dire ce que vous pensez qu'ils veulent que je fasse dans la fonction.
Merci.
Partager