CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Threaded View

  1. #1
    Join Date
    Jan 2010
    Posts
    1

    Constructor question

    I was writing a brief program testing scope with a class and discovered a line that I do not understand. I fixed the problem but my question remains.

    Here is my class.
    Code:
    class aClass
    {
    public:
      aClass()
      { 
    	  std::cout << "i'm alive\n";
      }
      ~aClass()
      { 
    	  std::cout << "i'm dead\n";
      }
    };
    Here is the fixed code. It ouputs "i'm alive" and "i'm dead" then finishes.
    Code:
    int main(int argc, char * argv[])
    {
      aClass A;
    }
    Here is my questionable code.
    Code:
    int main(int argc, char * argv[])
    {
      aClass A();
    }
    I thought that by using A() I would be calling it's constructor. The code compiles but outputs nothing. I tried overloading the () operator, with a similar short message but nothing was outputted. What is the code aClass A() doing? Newbie question, thanks.
    Last edited by Andreas Masur; January 31st, 2010 at 01:05 PM. Reason: Fixed code tags...

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured