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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Oct 2008
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Total newb C++ problem..

    I keep getting errors when I begin to include strings in my custom classes!! Actual program is more complex, but here's where I'm hitting problem.
    It's throwing all kind of exceptions concerning 'string' identifiers, missing type specifiers and missing ';'s. Thanks

    Driver.cpp:
    Code:
    #include <iostream>
    #include <string>
    
    #include "Custom.h"
    
    using namespace std;
    
    int main () {
    	Custom testClass ("test");
    	return 1;
    }
    Custom.h:
    Code:
    class Custom {
    	public:
    		Custom (string p_title);
    	private:
    		string title;
    }
    Custom.cpp:
    Code:
    #include <iostream>
    #include <string>
    
    #include "Custom.h"
    
    using namespace std;
    
    Custom::Custom (string p_title) {
    	title = p_title;
    }
    Last edited by TurkeyMaster77; 11-02-2008 at 07:50 PM.

  • #2
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    You need to put the include for the string header file and the using statement in the custom.h file before the class declaration. Header files should stand on their own and pull in any needed dependencies themselves.
    OracleGuy


  •  

    Posting Permissions

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