+ 1
Am trying to create a string attribute in Codeblocks but am told "string does not define a type"
I had created separate header and source files with codeblocks, made a string attribute in header file as private member, tried running code en it told me... What could be the issue? Sorry I can't post the piece of code!
8 odpowiedzi
+ 2
Did you include string?
Did you forget to use std:: ?
It's just guess work without you posting the code, m8.
+ 2
Okay. Thanks now I know. I'll be detailed nxt tym.
+ 1
I included string but never...wait do I need std:: to define an attribute?
+ 1
You don't need to use std:: to define an attribute, int doesn't need one after all.
It's because string is defined in the std namespace, so you have to tell the compiler where to look for it.
You probably used "using namespace std;" in your previous codes, which tells the compiler to look in std by default, so you never needed it.
However, you REALLY shouldn't do that in a header file as you'll pollute the global namespace for literally everyone that uses it.
You're not gonna make friends with that style.
( and you might as well use good coding practices, even when it's a private project )
You might have used it in your cpp file, but your header doesn't know about what goes on in there.
( codeblocks highlights most things defined in the std namespace as green, btw )
+ 1
So no string attributes for now...but I guess if I don't separate the code (as in header en source) it's possible to use string to define attributes...isn't it?
+ 1
All I'm saying is is that you should use std::string instead of just string if you want to use it.
+ 1
Let me give a try...
0
"Sorry I can't post the piece of code!"
Does this mean you don't know how? or is it something else?
Follow this guide for sharing links around SoloLearn forum, if it was for the former. Otherwise, it's rather difficult for any of us to assist you without having a look at your code. But it's your choice : )
https://www.sololearn.com/post/74857/?ref=app