Posted by: Sourav | August 10, 2014

class and object in visual C++


#include “stdafx.h”
#include <iostream>
using namespace std;
class test{

public:
    static
    int i;
    

};
int test::i=10;
class anothertest{
public:
    anothertest(int i,int j){
        cout<<“Hello the sum is “<<i+j<<endl;
    }

};

int _tmain(int argc, _TCHAR* argv[])
{
    test a;

    cout<<a.i<<endl;
    //objects are  value type here so can not use new operator
    anothertest ano=anothertest(5,6);
    anothertest *ano1=new anothertest(15,20);
    return 0;
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: