re: 函数指针实例 梦在天涯 2008-05-23 14:14 
			another samples:
#include "stdafx.h"
class Object;
typedef int (Object::*MemFuncPtr)(int, int);
typedef int (*StaticMemFuncPtr)(int, int);
class Object 
{
public:
    // non-static member
    int Add(int iFirst, int iSecond)
    {
        return iFirst + iSecond;
    }
    // static member
    static int Sub(int iFirst, int iSecond)
    {
        return iFirst - iSecond;
    }
    // 
    typedef int (Object::*InClassMemFuncPtr)(int, int);
    typedef int (*InClassStaticMemFuncPtr)(int, int);
};
int _tmain(int argc, _TCHAR* argv[])
{
    // Test non-static Add
    // 
    MemFuncPtr pfnMemFunc = &Object::Add;    
    // Need to bind the member function to a instance (need a this pointer)
    Object test;
    int res = (test.*pfnMemFunc)(1, 3);
    // function call missing argument list; use '&Object::Add' to create a pointer to member    
    //MemFuncPtr pfnMemFunc1 = test.Add;  
    //res = (test.*pfnMemFunc1)(1, 3);
    Object::InClassMemFuncPtr pfnMemFunc2 = &Object::Add;
    res = (test.*pfnMemFunc2)(1, 3);
    // Test Static Sub
    // 
    // cannot convert from 'int (__cdecl *)(int,int)' to 'MemFuncPtr'
    // Object::Sub Calling convention is __cdecl, but Object::*MemFuncPtr should be thisCall
    // function signature include calling convention, parameter list and return value..
    //pfnMemFunc = Object::Sub;
    //res = (test.*pfnMemFunc)(1, 3);
    StaticMemFuncPtr pfnStaticMemFunc = Object::Sub;
    res = (*pfnStaticMemFunc)(1, 3);
    StaticMemFuncPtr pfnStaticMemFunc1 = &Object::Sub;
    res = (*pfnStaticMemFunc1)(1, 3);
    Object::InClassStaticMemFuncPtr pfnStaticMemFunc2 = &Object::Sub;
res = (*pfnStaticMemFunc2)(1, 3);
    // stl ? how to use this “function pointer”???
    //std::mem_fun<int, Object>(&Object::Add);
//std::mem_fun<int, Object>(&Object::Sub);
    return 0;
}
				
		 
	
			re: 函数指针实例 梦在天涯 2008-05-23 12:33 
			成员函数指针:
#include "stdafx.h"
class CMemFuncPtr;
typedef int (CMemFuncPtr::*MemFuncPtr)(int, int);
class CMemFuncPtr 
{
public:
    int Add(int iFirst, int iSecond)
    {
        return iFirst + iSecond;
    }
};
int _tmain(int argc, _TCHAR* argv[])
{
    MemFuncPtr pfnMemFunc = &CMemFuncPtr::Add;
    CMemFuncPtr test;
    (test.*pfnMemFunc)(1, 3);
    
    return 0;
}
				
		 
	
			re: C++拷贝构造函数的几个细节 梦在天涯 2008-05-12 09:00 
			@张某某
就想一般的函数重载一样啊,你没有重载那个版本的,你就不能用哦!
				
		 
	
			
			haha,这个targetver.h只有在08才有的把!
				
		 
	
			re: 谈谈C/C++和.NET以后的走向 梦在天涯 2008-04-28 09:12 
			haha,现在的工作用C+++C#,觉得这连个可以了应该吃饭没有问题把!
				
		 
	
			
			因为result编译器不知道是static变量还是类型,所以必须要typename来申明是类型!
				
		 
	
			re: 内存池(version1.1) 梦在天涯 2008-04-22 09:17 
			Modern C++ design有点高深哦!共同研究,共同进步哦!非常感谢分享!
				
		 
	
			
			还有可以通过CLI的封装,可以看我的blog上有些资料啊!
				
		 
	
			re: C++、VC-迷茫 梦在天涯 2008-04-16 15:01 
			看工作需要了,不过据统计现在用java的最多啊,但是学的人多了,工资不一定是最高的哦!
				
		 
	
			re: 如何阅读、使用Blog? 梦在天涯 2008-04-16 09:14 
			我现在用www.inezha.com也很方便!
没有更新会自动发到我的msn上,一点就搞定可!
				
		 
	
			re: 单元测试PPT讲义 梦在天涯 2008-04-09 09:19 
			修改代码的艺术,确实是艺术!
单元测试,难的是正真的在项目中实行!
				
		 
	
			
			一直没有编过,今天看lz说的这么仔细,太好了,以后有机会一定一试啊!
				
		 
	
			re: 猜猜看,id变成9了吗? 梦在天涯 2008-04-02 10:02 
			    ((TestStr)(*p_ts)).SetId(9);      //编译通过
    ((TestStr)(*p_ts)).id = 9;         //编译不通过
    (&((TestStr)(*p_ts)))->id = 9; //编译通过
我在VS2005下:
正如作者所说中间的是编不过的,error,说是l-value不能赋值。
但是能编过的2个结果都还是1,没有修改了原来的值,因为在类型转化的时候都调用了拷贝构造函数,从新生成一个对象你修改的是拷贝后的临时对象。(你可以写拷贝构造函数测试一下)
所以同意:
这其实相当于调用了TestStr(const TestStr&)生成了一个TestStr&的临时变量。
C++标准规定,类性转换表达式的目标类型为引用时,结果为l-value;否则为r-value。
				
		 
	
			
			可能是写的过程中有错,所以你要flash一下io或重设io的状态!
				
		 
	
			
			functor 确实是比STL中的一大堆好用多了!统一!
				
		 
	
			re: GCC4.3... 梦在天涯 2008-03-14 11:42 
			GCC4.3中带有c++ox吗,那我也下个啊,vs的话要等到vs2008了
				
		 
	
			re: 卖书 梦在天涯 2008-02-18 17:09 
			我也有一个C#primer 和C#设计模式,有谁要的话也联系我啊!我的2本都半价。
				
		 
	
			re: 好又多刷卡奇遇记 梦在天涯 2008-02-03 11:05 
			那最后确定了吗,真的是多刷了吗,真可怕啊!
所以以后刷卡呀一定要在旁边看着啊!