Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Oct 2008
    Posts
    102
    Thanks
    28
    Thanked 4 Times in 4 Posts

    expected unqualified error problem

    C:\Documents and Settings\Administrator\Desktop\cpp\tryingClasses\main.cpp|5|error: expected unqualified-id before "using"|
    C:\Documents and Settings\Administrator\Desktop\cpp\tryingClasses\main.cpp||In function `int main()':|
    C:\Documents and Settings\Administrator\Desktop\cpp\tryingClasses\main.cpp|14|error: `cout' was not declared in this scope|
    C:\Documents and Settings\Administrator\Desktop\cpp\tryingClasses\main.cpp|14|error: `endl' was not declared in this scope|
    ||=== Build finished: 3 errors, 0 warnings ===|


    PHP Code:
    #include <iostream>
    #include <string>
    #include "person.h"

    using namespace std;



    int main()
    {
        
    person david("david");
        
    person brhams("bhrams"34);

        
    cout << "name: " << brhams.getName() << " age: " << brhams.getAge() << endl << endl;

        
    david.setAge(20);
        
    david.setName("David Lebee");

        
    cout << "fullname: " << david.getName() << " age: " << david.getAge() << endl << endl;

        return 
    0;


  • #2
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    The problem is in person.h, I bet you forgot the semicolon off the end of your class declaration.
    OracleGuy

  • #3
    Regular Coder BrickInTheWall's Avatar
    Join Date
    Mar 2009
    Location
    Munich, Germany
    Posts
    139
    Thanks
    1
    Thanked 13 Times in 13 Posts
    Quote Originally Posted by oracleguy View Post
    The problem is in person.h, I bet you forgot the semicolon off the end of your class declaration.
    I was just about to say that ...this happens to me a lot and being a beginner I would always look for the error for several minutes...

    Code:
    class ClassName{
    // Members, Methods, Constructor, Destructor etc.
    };   <------

  • #4
    New Coder
    Join Date
    May 2009
    Posts
    28
    Thanks
    9
    Thanked 0 Times in 0 Posts
    wait, i want to try this out, so what are we supposed to change XD

  • #5
    Regular Coder BrickInTheWall's Avatar
    Join Date
    Mar 2009
    Location
    Munich, Germany
    Posts
    139
    Thanks
    1
    Thanked 13 Times in 13 Posts
    Quote Originally Posted by saadhamza View Post
    wait, i want to try this out, so what are we supposed to change XD
    you should check your class declaration and see if you forgot to add the semicolon at the end of it.
    from dsylebee's code you can see what methods the class contains...ones to set the name, one to display the name, one to set the age and one to display the age...maybe there are more methods that aren't used right now but just from the code in his main function you can see the basic way his class works. Since he is using methods to change class members you can assume these to be private...otherwise he could just use brahms.age (assuming the age variable member is called "age") to retrieve it rather than using a method to do so.
    Last edited by BrickInTheWall; 07-03-2009 at 02:16 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •