C++的名空间问题

来源:百度知道 编辑:UC知道 时间:2024/06/10 04:07:03
#include<stdio.h>
#include<iostream.h>
#include<conio.h>
#include<math.h>
#include<string.h>

class A
{
public:
char *CCC;
void *P;
void F()
{}

};

void main()
{
A A_0;
char *C;
C=A_0.CCC;//成功。

void *P_5;
P_5=A_0.P;//成功。

void *P_0,(*P_1)();
P_0=P_1;
// P_1=A_0.F;//error C2440: '=' : cannot convert from 'void (__thiscall A::*)(void)' to 'void (__cdecl *)(void)'
// P_0=A_0.F;//error C2440: '=' : cannot convert from 'void (__thiscall A::*)(void)' to 'void *'
/*
上面的直接赋值不行,因为名空间不同。
*/

// void A::*P_2;//error C2182: '<Unknown>' : illegal use of type 'void'是什么意思?
int A::*P_2;
int *P_3;
void (A::*P_4)();
// P_3=P_2;//error C2440: '=' : cannot convert from 'int A::*' to 'int

一个是成员函数,一是全局函数,当然不能直接将函数指针直接赋值了。要取成员函数地址很麻烦,具体参照:
http://www.vckbase.com/document/viewdoc/?id=1818

基本上我也没有看懂

顶顶啊,实在没办法的话就把分给我吧

我觉的你的程序没有问题