作者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