看板 EE_DSnP 關於我們 聯絡資訊
Dear All: 在這個範例中,若 A* b = new A[10]; 在main中傳回來的位址是 b = 10*sizeof(A)+4 ; 其中多出的四個 BYTE 是用來存放 10 的嗎? 可是我用 cout << *b << endl; 看到的卻是亂碼,請問我錯在哪? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.112.4.234
ric2k1:Please print out *(address(b) - 4)... 12/06 16:40
ric2k1:I don't mean "cout << *(address(b) - 4) << endl; 12/06 16:40
ric2k1:Please figure out a way to print it! 12/06 16:41
suspect1:再給點提示嗎?我用了*(size_of(b)-4)編譯不過 12/06 18:13
suspect1:打錯了@@ *(size_t(b)-4) 12/06 18:15
ric2k1:size_t(b) ==> becomes a size_t variable 12/06 18:31
ric2k1:size_t(b) - 4 ==> the "content" of (size_t(b)) - 4 12/06 18:32
ric2k1:size_t(b) - 4 ==> still a size_t type variable 12/06 18:32
ric2k1:*(size_t(b) - 4) ==> (size_t(b) - 4) is NOT a pointer 12/06 18:33
ric2k1:That's why you have compilation error 12/06 18:34
ric2k1:Try to start with (size_t*)b.... that's all I can say. 12/06 18:34
ric2k1:More question, please see me in person... 12/06 18:36
suspect1:謝謝老師~終於對了! 12/07 00:16
ric2k1::) 12/07 01:23