作者suspect1 (嫌犯)
看板EE_DSnP
標題[問題] newOp.cpp的問題
時間Wed Dec 6 14:21:02 2006
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
1F:推 ric2k1:Please print out *(address(b) - 4)... 12/06 16:40
2F:→ ric2k1:I don't mean "cout << *(address(b) - 4) << endl; 12/06 16:40
3F:→ ric2k1:Please figure out a way to print it! 12/06 16:41
4F:推 suspect1:再給點提示嗎?我用了*(size_of(b)-4)編譯不過 12/06 18:13
5F:→ suspect1:打錯了@@ *(size_t(b)-4) 12/06 18:15
6F:推 ric2k1:size_t(b) ==> becomes a size_t variable 12/06 18:31
7F:→ ric2k1:size_t(b) - 4 ==> the "content" of (size_t(b)) - 4 12/06 18:32
8F:→ ric2k1:size_t(b) - 4 ==> still a size_t type variable 12/06 18:32
9F:→ ric2k1:*(size_t(b) - 4) ==> (size_t(b) - 4) is NOT a pointer 12/06 18:33
10F:→ ric2k1:That's why you have compilation error 12/06 18:34
11F:→ ric2k1:Try to start with (size_t*)b.... that's all I can say. 12/06 18:34
12F:→ ric2k1:More question, please see me in person... 12/06 18:36
13F:推 suspect1:謝謝老師~終於對了! 12/07 00:16
14F:推 ric2k1::) 12/07 01:23