#include <stdio.h> class Woman{ //making it friend friend void loveWoman(); private: int age; int salary; public: char name[50]; void walk(); }; //friend function void loveWoman(){ Woman myGirlFriend; // access private member variables printf("My girlfriends age:%i \n",myGirlFriend.age); // access public member variables printf("My girlfriends age:%i \n",myGirlFriend.name); } //not a friend function void hateWoman(){ Woman myhusbandXWife; // only can access public member variables printf("My girlfriends age:%i \n",myhusbandXWife.name); } void main(){ //call friend non member function loveWoman(); //call non member function hateWoman(); }
Pages - Menu
▼
Tuesday, May 29, 2012
Access member variable from non member function in C++
Friend non member function can access private member variable also. following example help you to understand how to use friend keyword and how to access member private variables from non member function.
Sunday, May 27, 2012
SQL Server Tips
1. How to get list of stored procedures in a database
2. How to get list of tables in a database
3. How to get list of databases in a SQL server
SELECT NAME FROM SYS.ALL_OBJECTS WHERE type= 'P'
2. How to get list of tables in a database
SELECT * from sysobjects where type = 'U'
3. How to get list of databases in a SQL server
SELECT name, collation_name FROM sys.databases WHERE name NOT IN ('master', 'tempdb', 'model', 'msdb')
Wednesday, May 23, 2012
How to convert integer number to a binary string in C++.
Converting integer to binary string is a very simple matter. for this there is a special class call "bitset".
so fallow the example bellow and try to play around "bitset"
For more information visit http://www.cplusplus.com/reference/stl/bitset/
so fallow the example bellow and try to play around "bitset"
For more information visit http://www.cplusplus.com/reference/stl/bitset/
#include <iostream> #include <bitset> void main(){ //creating instance using bitset (16 bit). here you can specify the length suc as 8,16,32,64... std::bitset< 16 > btFlaged; //assigning integer values to instance btFlaged = 1234; //print bit string in the string for(int i =0; i< btFlaged.size(); i++){ std::cout <<btFlaged.test(i) << std::endl; } }