2012.1.3 void指针

#include <afx.h>
#include <iostream>
#include <string>
#include <vector>
#include <io.h>
#include <stdio.h>
#include <fcntl.h>
#include <boost/filesystem.hpp>

#include <iostream>
#include <boost/thread/thread.hpp>
#include <string>
#include <vector>
#include <boost/algorithm/string.hpp>
#include <boost/lexical_cast.hpp>
#include <fstream>
#include <exception>

using namespace std;
using namespace boost;
using namespace boost::filesystem;
using namespace boost::algorithm;

int main()
{
 void *p1;
 int *p2 = new int;
 float *p3;

 p1 = p2;  //其他类型的指针可以赋值给void指针
 *p2 = 3;
 cout<<reinterpret_cast<int *>(p1)<<endl<<*reinterpret_cast<int *>(p1);//void指针可以赋值给类型指针,但是要强制转化
 p3 = (float *)p1; //void指针可以赋值给类型指针,但是要强制转化

}

posted @ 2012-01-03 19:25  rookieeeeee  阅读(177)  评论(0编辑  收藏  举报