Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   how to use explicit keyword in C++ (http://www.go4expert.com/forums/explicit-keyword-cpp-t22121/)

shyam_oec 17May2010 13:54

how to use explicit keyword in C++
 
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 18May2010 14:15

Re: how to use explicit keyword in C++
 
Usage looks OK. What compiler are you using? Is it one that doesn't support the "explicit" keyword?

shyam_oec 19May2010 07:00

Re: how to use explicit keyword in C++
 
I am using Turbo C++ version 3. Which version should i use?
Thanks.

xpi0t0s 19May2010 12:12

Re: how to use explicit keyword in C++
 
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 20May2010 14:02

Re: how to use explicit keyword in C++
 
I have Visual Studio 2008. But i don't know how to create C++ application on them.Can you guide?
Thanks,

xpi0t0s 20May2010 14:52

Re: how to use explicit keyword in C++
 
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.


All times are GMT +5.5. The time now is 10:59.