由买买提看人间百态

topics

全部话题 - 话题: aptr
(共0页)
d****n
发帖数: 1637
1
Sorry being a noobie.
this should be what I was talking about.
the 1st version was wrong.
#######################################
#include
void swap(void **firstPtr, void **secondPtr)
{
void *temp = *firstPtr;
*firstPtr = *secondPtr;
*secondPtr = temp;
return;
}
int main()
{
int a = 10;
int b = 20;
int *aPtr = &a;
int *bPtr = &b;
printf("Before Swapping, Address : %x %x, Value : %d %d\n", aPtr, bPtr,
*
aPtr, *bPtr);
swap(&aPtr, &bPtr);
printf("After Swapping, Address : %x %x, Value : %... 阅读全帖
s****n
发帖数: 1237
2
来自主题: Programming版 - 请教个virtual function的问题
下面这段代码输出的是 Class B func1 x = 2, 我有几个疑问
1. 为啥调用的是B的func1但是x却是用了A的缺省值?
2. B的func1我特地设为private,为啥还是能调用?我试过直接B ojbB,就不能用ojbB
.func1();
3. 这里面涉及哪些相关的知识点,有什么好的quick tutorial可以推荐。
谢谢。
#include
using namespace std;
class A
{public:
virtual void func1 (int x = 2) {
cout << "Class A func1 x = " << x << "\n";
}
};
class B: public A
{private:
virtual void func1 (int x = 8){
cout <<"Class B func1 x = " << x << "\n";
}
};
void main () {
A *aPtr = new B;
aPtr -> func
(共0页)