Thread: struct problem

  1. #1
    Registered User
    Join Date
    Jun 2007
    Posts
    12

    Question struct problem

    I'm having some problems defining a structure, can anyone help

    this bit is in the header file

    Code:
    #include <string>
    
    
    struct netData{
    public:
    	unsigned short int time;
    	unsigned short int dTime;
    	string path;
    	float prob;
    	float conc;
    	bool alarm;
    	netData *nxt;
    };
    for some reason the compiler doesn't like me putting a string declaration into a struct. these are the errors generated.

    c:\work\programming\nettest\nt.h(40) : error C2146: syntax error : missing ';' before identifier 'path'
    c:\work\programming\nettest\nt.h(40) : error C2501: 'string' : missing storage-class or type specifiers
    c:\work\programming\nettest\nt.h(40) : error C2501: 'path' : missing storage-class or type specifiers

  2. #2
    Massively Single Player AverageSoftware's Avatar
    Join Date
    May 2007
    Location
    Buffalo, NY
    Posts
    141
    string is the std namespace.

    Try:
    Code:
    std::string path;
    There is no greater sign that a computing technology is worthless than the association of the word "solution" with it.

  3. #3
    Registered User
    Join Date
    Jun 2007
    Posts
    12
    Thanks

    I did include the std namespace in the main file, but overlooked that the header file would get prcessed before encountering that bit

    as Homer would say DOHHH

  4. #4
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Quote Originally Posted by spudval View Post
    Thanks

    I did include the std namespace in the main file, but overlooked that the header file would get prcessed before encountering that bit

    as Homer would say DOHHH
    It shouldn't matter in what order and where header files are included. Therefore keep in mind to prefix std:: to std namespace things in headers.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    I prefer to always type std::string. Then I don't have to worry about it.

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    You certainly don't want to put
    using namespace std;
    inside a .h file.

    Anyone using your header file would get the whole std namespace whether they wanted it or not.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #7
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Code:
    struct netData{
    public:
    ...
    };
    structs are public by default.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Struct File and array problem Please help
    By theprogrammer in forum C Programming
    Replies: 17
    Last Post: 04-02-2009, 08:05 AM
  2. memory issue
    By t014y in forum C Programming
    Replies: 2
    Last Post: 02-21-2009, 12:37 AM
  3. Link List math
    By t014y in forum C Programming
    Replies: 17
    Last Post: 02-20-2009, 06:55 PM
  4. Replies: 22
    Last Post: 12-23-2008, 01:53 PM
  5. Replies: 16
    Last Post: 10-29-2006, 05:04 AM