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;
}
//
#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
Post a Comment