Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Programming Talk / C++ / C# - String library included; compiler still won't recognize "string" declaration

Author
Message
Rudolpho
20
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 2nd Oct 2009 19:18 Edited at: 2nd Oct 2009 19:18
I've tried it all by now, it's starting to feel like.

So, I've got this (which is in turn a header file included by the main header file, which is included by the main source):


header.h also has #pragma once declared, by the way.
I'm not all new to C++, but am new to using classes and separate source files (I've previously used these concepts in Java though).

So, what happens? The compiler fails, telling me
Quote: "error C2146: syntax error : missing ';' before identifier 'name'"

at the specified line (the one declaring the strings).
My conclusion is that it doesn't recognize the string class as a valid type identifier or whatever you call it.
I've tried messing about with this for the last hour, moving inclusion statements here and there between my files, but no luck.
I was thus hoping that someone more experienced could tell me what is wrong and, if possible, what to do about it.

Thanks,
Rudolpho

Sven B
21
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 2nd Oct 2009 19:43
Perhaps you're forgetting the namespace?
Correct declaration would be:
std::string name, desc;

Sven B

Diggsey
20
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 3rd Oct 2009 00:59
Or alternatively, you could do one of the following:

using std::string;
using namespace std;

Rudolpho
20
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 3rd Oct 2009 01:12
Aw, now that's embarrasing, as I've definitively used namespaces before

Ah well, thanks for pointing it out!

NeX the Fairly Fast Ferret
21
Years of Service
User Offline
Joined: 10th Apr 2005
Location: The Fifth Plane of Oblivion
Posted: 3rd Oct 2009 15:14
With C, you can shoot yourself in the foot.

With C++, you can reuse your foot anywhere, and it's kept in its own little space. As a consequence, you can no longer shoot yourself directly in the foot and any shots directed at it loop round and hit you in the back of the head.

Login to post a reply

Server time is: 2026-06-10 03:29:58
Your offset time is: 2026-06-10 03:29:58