Help about constructor.

Hello everyone, I do not understand why this program does not print the number 7 when it is running, or am I misunderstanding sth here?
I am just a beginner in C++, and I am looking forward to receive any advice and opinions.
Thank you in advance, and have a nice day. :)


// ConsoleApplication1.cpp : Defines the entry point for the console application.
// Class practice 1

#include "stdafx.h"
#include <iostream>
using namespace std ;

class Package
{
private:
int value ;
public:
Package()
{
value = 7 ;
cout << value << endl ;
}

Package(int v)
{
value = v ;
cout << value << endl ;
}

~Package()
{
cout << value << endl ;
}
} ;

int _tmain(int argc, _TCHAR* argv[])
{
Package obj1(4) ;
Package obj2() ;
Package obj3(2) ;

cin.get() ;
cin.get() ;
return 0;
}

Package obj2();
This is a function declaration of a function named obj2 that returns a Package and takes no arguments. Just leave out the parentheses and it will work.
Package obj2;
Topic archived. No new replies allowed.