Static Function
// staticfun.cpp : Defines the exported functions for the DLL application.
//
#include "stdafx.h"
#include <iostream>
class c1
{
static int resource;
public:
static int get_resource();
void free_resou()
{
resource = 0;
}
};
int c1::resource;
int c1::get_resource()
{
if(resource)
return 0;
else
resource = 1;
return 1;
}
int main()
{
c1 obj1, obj2;
if(c1::get_resource())
std::cout << "resource occupied by obj1";
if(!c1::get_resource())
std::cout << " resource denied";
obj1.free_resou();
if(c1::get_resource())
std::cout << " resouce occpied by obj2";
}
//
#include "stdafx.h"
#include <iostream>
class c1
{
static int resource;
public:
static int get_resource();
void free_resou()
{
resource = 0;
}
};
int c1::resource;
int c1::get_resource()
{
if(resource)
return 0;
else
resource = 1;
return 1;
}
int main()
{
c1 obj1, obj2;
if(c1::get_resource())
std::cout << "resource occupied by obj1";
if(!c1::get_resource())
std::cout << " resource denied";
obj1.free_resou();
if(c1::get_resource())
std::cout << " resouce occpied by obj2";
}
Comments
Post a Comment