CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Aug 2006
    Posts
    144

    [solved]29: error: ‘string’ does not name a type

    Hi,

    when try to compile my program I get the following message for this header file

    Code:
    #ifndef SENDSMS_H
    #define SENDSMS_H
    
    #include "ui_sendSMS.h"
    #include <string>
    
    
    class sendSMS : public QMainWindow, public Ui::MainWindow{
    	Q_OBJECT
    
    public:
    	sendSMS (QMainWindow *parent = 0);
    	~sendSMS();
    private slots:
    	void slotClose();
    	void calcChar();
    	void slotSend();
    	QString clean_string(QString);
    	QChar get_param(QString, int);
    	QString get_param_value(QString, int);
    	void process_line(QString);
    	void read_config_file();
    
    private:
    	int maxChar;
    	QString param_filename;
    	string username;
    	string password;
    	string sourceno;
    	
    };
    
    #endif
    Ignore all the "Q" things, thats something Qt specific. int works fine, but not string. I have the string header included. I guess it is rather simple what is wrong....

    Thanks,
    J.
    Last edited by joebar; August 26th, 2007 at 04:12 AM.

  2. #2
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    Re: 29: error: ‘string’ does not name a type

    Use std::string instead of the unqualified string.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  3. #3
    Join Date
    Aug 2005
    Posts
    132

    Re: 29: error: ‘string’ does not name a type

    Another option is to use the following

    Code:
    use namespace std;
    One contentions issue is whether or not you should use namespace declarations in code, personally I find them confusing and laserlight's method is the one I choose to use, especially when dealing with multiple namespaces.

  4. #4
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,654

    Re: 29: error: ‘string’ does not name a type

    The use of namespace in headers is not recommended so go for laserlight's suggestion.

  5. #5
    Join Date
    Aug 2006
    Posts
    144

    Re: 29: error: ‘string’ does not name a type

    Hi,

    thanks, but why is it not recommended? What is the problem here?

    Thanks,
    J.

  6. #6
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,654

    Re: 29: error: ‘string’ does not name a type

    Namespaces are meant to be used to separate things to avoid name clashes. If you in the future need to use two or more namespaces that have name clashes and all your headers already set a namespace you can't resolve this without editing the headers. I.e. it defeats the purpose of namespaces and it's very bad in a maintainance perspective.

    I guess that not using "use namespace" at all as GuOddian say is the safest way to go but it also requires some extra typing that can be saved to when it's actually needed (names actually clash)

  7. #7
    Join Date
    Sep 2006
    Location
    Sunshine State
    Posts
    517

    Re: 29: error: ‘string’ does not name a type

    Another way would be:
    Code:
    using std::string;
    That way you only import the string.

  8. #8
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    Re: 29: error: ‘string’ does not name a type

    That way you only import the string.
    That is still generally a Bad Thing in a header file.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  9. #9
    Join Date
    Aug 2005
    Location
    Netherlands, The
    Posts
    2,184

    Re: 29: error: ‘string’ does not name a type

    i agree with laserlight

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured