too many types in declaration

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AYESHA Jabeen
    New Member
    • Jun 2011
    • 1

    too many types in declaration

    it is a simple program that is demonstrating class and object.but it is giving an error like too many types in declaration and function should return a value....
    pls find solution and suggest me what should i do...

    Code:
    #include<iostream.h>
    #include<conio.h>
    
    class ayes
    {
    public:
    void foo()
    {
    int a,b;
    cout<<"Enter two nos:";
    cin>>a>>b;
    cout<<a+b;
    }
    }
    Last edited by Niheel; Jun 21 '11, 05:13 AM. Reason: code ags
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    #2
    public: preceds a list of member variables and class declarations.
    You have not listed any so the following function is being read as such.

    Comment

    • Banfa
      Recognized Expert Expert
      • Feb 2006
      • 9067

      #3
      @code green, it is completely acceptable in language syntax to place the body of a method inside a class declaration as has been done, although it is normally reserved for short methods as methods declared like that are automatically inlined.

      @AYESHA Jabeen, you use iostream.h, this header was deprecated in 1999 with the release of the C++ standard. You should be using iostream (note no .h). conio.h is not a standard header and you don't seem to be using anything from it either. If you do switch headers remember you will need to access the std name space to reference cin and cout.

      You are missing a ; on line 14. Part from that I see little wrong and it compiles with that error fixed.

      Comment

      • jaseel97
        New Member
        • Feb 2015
        • 16

        #4
        Put semicolon after the class declaration. That should do the trick.

        Comment

        Working...