top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to print "Hello C++" with empty main() in C++? Without using class.

+1 vote
451 views
How to print "Hello C++" with empty main() in C++? Without using class.
posted Jul 18, 2017 by Ajay Kumar

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+2 votes
  • Define a class and in the constructor print "Hello C++"
  • Instantiate the class at the time of the definition so that it executes before the main.

Sample code

#include <iostream>
using namespace std;

class MyClass
{
        public:
                MyClass()
                {
                        cout << "Hello C++";
                }
} myclass;

int main()
{

}
answer Jul 19, 2017 by Salil Agrawal
...