how to use explicit keyword in C++

shyam_oec's Avatar, Join Date: Nov 2007
Contributor
Hi,
please have a look at this code.

Code:
 class A {
        public:
                explicit A(int);
        };

main()
{
A obj=8;
}
While compiling i am getting error "Type name expected" at "explicit" keyword.
What could be the possible reason and its solution?

Thanks
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
Usage looks OK. What compiler are you using? Is it one that doesn't support the "explicit" keyword?
shyam_oec's Avatar, Join Date: Nov 2007
Contributor
I am using Turbo C++ version 3. Which version should i use?
Thanks.
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
Certainly not an ancient compiler that was actually coded by a dinosaur, that's for certain.

You will need to use a modern compiler if you want to use modern languages. gcc does a good job of keeping up with the times, or you could use the Microsoft compilers (downloadable for free from MSDN).
shyam_oec's Avatar, Join Date: Nov 2007
Contributor
I have Visual Studio 2008. But i don't know how to create C++ application on them.Can you guide?
Thanks,
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
It's really not hard. File -> New -> Project; in Project Types pick Win32 under Visual C++.
What happens next depends on what kind of project you want. Given that your ability is such that you can't find File New Project, I suggest starting with the template Win32 Console Application.
Give it a name and location, it will create a basic project that you can build and run (maybe after adding a line to display Hello World) using the cunningly named menu Build -> Build Solution. After building, fix any compile errors, then use the menu Debug -> Start Without Debugging to run the program.