1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

how to use explicit keyword in C++

Discussion in 'C++' started by shyam_oec, May 17, 2010.

  1. shyam_oec

    shyam_oec New Member

    Joined:
    Nov 26, 2007
    Messages:
    89
    Likes Received:
    1
    Trophy Points:
    0
    Occupation:
    Software Developer, .NET Framework
    Location:
    Jamshedpur
    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
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    Usage looks OK. What compiler are you using? Is it one that doesn't support the "explicit" keyword?
     
  3. shyam_oec

    shyam_oec New Member

    Joined:
    Nov 26, 2007
    Messages:
    89
    Likes Received:
    1
    Trophy Points:
    0
    Occupation:
    Software Developer, .NET Framework
    Location:
    Jamshedpur
    I am using Turbo C++ version 3. Which version should i use?
    Thanks.
     
  4. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    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).
     
  5. shyam_oec

    shyam_oec New Member

    Joined:
    Nov 26, 2007
    Messages:
    89
    Likes Received:
    1
    Trophy Points:
    0
    Occupation:
    Software Developer, .NET Framework
    Location:
    Jamshedpur
    I have Visual Studio 2008. But i don't know how to create C++ application on them.Can you guide?
    Thanks,
     
  6. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    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.
     

Share This Page