Thread: Error: "String does not name a type", confused

  1. #1
    Linux Forever
    Join Date
    Oct 2002
    Posts
    373

    Error: "String does not name a type", confused

    Code:
    #ifndef CLASS_H_
    #define CLASS_H_
    #include <string>
    #include "stat.h"
    
    typedef struct
    {
    	string name;
    	Stat_Set stats;
    	string desc;
    }Clss;
    
    #endif
    string name; and string desc; have this error output:

    " 'string' does not name a type' ".

    At first I thought I had forgotten to include <string>, but I was able to quickly rule that out.

    Thanks in advance.
    This war, like the next war, is a war to end war.

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    491
    std::string
    Go read the section of some FAQ on namespaces.

  3. #3
    Registered User
    Join Date
    Nov 2002
    Posts
    491
    typedef'ing a struct is also fairly useless in C++ as well.

  4. #4
    Linux Forever
    Join Date
    Oct 2002
    Posts
    373
    Yea I know about the typedef being useless... habit from my Atari ST days.

    I'm using namespace std in all other files.. I'm amazed that I forgot it in this one... lol.

    Well, that got rid of that error. Now it's got a bunch of "Redefined" errors. Which is BS.

    Ill put it all in one file and test it.
    This war, like the next war, is a war to end war.

  5. #5
    Linux Forever
    Join Date
    Oct 2002
    Posts
    373
    Ah this program just went Foo-bar. Absolutely will not work. I madea new function,
    Code:
    void foo() 
    {
    cout << "foo";
     }
    Just once. "Redefined here" on it. First function. Which is BS. C++ hates me, like everything else :/
    This war, like the next war, is a war to end war.

  6. #6
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    You cannot define a function in a header file included by multiple source files (unless it is inlined). Place the function definition in the source file and the declaration (prototype) in the header file if you want it to be used in multiple places.

  7. #7
    Linux Forever
    Join Date
    Oct 2002
    Posts
    373
    I did, the foo function was in the main source file, and I removed all other remmanants of the old program. Still got the same result. I think CodeForge may have a bug, but then, it's not the program doing the compiling, so I don't know.. no idea.. not one...
    This war, like the next war, is a war to end war.

  8. #8
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    If you post your code somebody may be able to help. Redefinition error means that the definition was included in multiple source files or included multiple times in the same source file.

  9. #9
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    You might want to use inclusion guards.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Confused with array size
    By desmond5 in forum C Programming
    Replies: 4
    Last Post: 12-04-2007, 05:14 PM
  2. New to C++ and confused by boolean and ifs and else
    By jconner in forum C++ Programming
    Replies: 10
    Last Post: 08-02-2006, 03:29 AM
  3. Confused
    By (TNT) in forum C# Programming
    Replies: 1
    Last Post: 11-23-2005, 04:49 PM
  4. So Now Im getting confused?!?!?
    By zergdeath1 in forum C++ Programming
    Replies: 11
    Last Post: 03-06-2004, 05:41 PM
  5. confused.. in selecting my line of deapth
    By jawwadalam in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 05-04-2003, 01:21 PM