Pointer To member class

// Pointerto_MemClass.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>

class ptrToMemClass
{
public:
int value;
ptrToMemClass(int a)
{
value = a;
}
int doubleval()
{
return value + value;
}
};

int _tmain(int argc, _TCHAR* argv[])
{
int ptrToMemClass::*data;
int (ptrToMemClass::*func)();

ptrToMemClass obj1(25),obj2(50);

data = &ptrToMemClass::value;
func = &ptrToMemClass::doubleval;

std::cout<< obj1.*data << "  " << obj2.*data ;
(obj1.*func)();
(obj2.*func)();



return 0;
}

Comments

Popular posts from this blog

Smart Pointers in C++ and How to Use Them

Operator Overloading in C++

How would you read in a string of unknown length without risking buffer overflow