-
October 13th, 2003, 06:56 AM
#1
Problems using the STL list template
Hello all,
I'm trying to use the STL list template class in some code of mine and I get weird errors, or at least they look weird to me. I'm properly including the list header at the beginning of my file (#include <list>) and when I try to declare a list with "std::list<mytype> mylist;" the compiler is telling me that list isn't in the std namespace.
I am using Visual C++ 7.0. Am I doing something stupid or is this a known bug?
Thanks in advance,
Maxime
-
October 13th, 2003, 08:14 AM
#2
That looks as if it should work fine.
What is the exact error message?
What is the definition of mytype?
Can you post the code?
Dave Mclelland.
-
October 13th, 2003, 08:19 AM
#3
Re: Problems using the STL list template
Originally posted by mux
with "std::list<mytype> mylist;" the compiler is telling me that list isn't in the std namespace.
Did you forget to put:
Code:
using namespace std;
At the beginning of the header where you declare your STL based objects (vector/list/whatever..)?
Sid
-
October 13th, 2003, 08:55 AM
#4
Originally posted by Dave McLelland
That looks as if it should work fine.
What is the exact error message?
What is the definition of mytype?
Can you post the code?
The exact error message is "'list' : is not a member of 'std'".
mytype is a rdv_t, which is a typedef on a struct.
I'm sorry, I can't post the code here, and I'm really sorry to say this, being an opensource developper the night... But the day I have to do VC++ for my employer and can't disclose the code :-(.
The code looks like this :
#include <list>
// Other headers here.
typedef struct CRdv_t {
// Some stuff here.
} rdv_t;
// Various methods here.
SomeType
SomeObject::SomeMethod(SomeParameters) {
// Other variables definition.
std::list<rdv_t> mylist;
// Body of the method.
}
It chokes on the std::list<rdv_t> mylist; as described above.
The code looks really correct to me, I'm puzzled :-(.
Cheers,
Maxime
-
October 13th, 2003, 09:03 AM
#5
Originally posted by mux
The exact error message is "'list' : is not a member of 'std'".
mytype is a rdv_t, which is a typedef on a struct.
I'm sorry, I can't post the code here, and I'm really sorry to say this, being an opensource developper the night... But the day I have to do VC++ for my employer and can't disclose the code :-(.
The code looks like this :
#include <list>
// Other headers here.
typedef struct CRdv_t {
// Some stuff here.
} rdv_t;
// Various methods here.
SomeType
SomeObject::SomeMethod(SomeParameters) {
// Other variables definition.
std::list<rdv_t> mylist;
// Body of the method.
}
It chokes on the std::list<rdv_t> mylist; as described above.
The code looks really correct to me, I'm puzzled :-(.
Cheers,
Maxime
Hate to repeat myself! :-)
I don't see this line:
Code:
using namespace std;
Please put it, and then check!
-
October 13th, 2003, 09:10 AM
#6
Originally posted by Siddhartha
Hate to repeat myself! :-)
I don't see this line:
Code:
using namespace std;
Please put it, and then check!
As far as I can tell, this line is absolutely not needed since I'm not trying to access the list template as list but as std::list. Besides, I already said in this thread that putting this line didn't help at all.
Cheers,
Maxime
-
October 13th, 2003, 09:10 AM
#7
That should work (works here).
Do a preprocessed listing to a file and see what is actually being produced.
Can you post the actual code from the function declaration to the line after the std::list?
Dave Mclelland.
-
October 13th, 2003, 09:15 AM
#8
Originally posted by Siddhartha
Hate to repeat myself! :-)
I don't see this line:
Code:
using namespace std;
Please put it, and then check!
Since he uses the qualified name std::list, he doesn't have to use using namespace std.
To mux: Your problem must be elsewhere. Are any of your class declarations not followed by a semicolon ? Are you inside of another namespace ?
The following code compiles just fine (to show that what you posted can't be the problem):
Code:
#include <list>
// Other headers here.
typedef struct CRdv_t {
int i;
} rdv_t;
// Various methods here.
class CSomeObject
{
public:
int SomeMethod(int a);
};
int CSomeObject::SomeMethod(int a) {
// Other variables definition.
std::list<rdv_t> mylist;
// Body of the method.
return 0;
}
int main()
{
CSomeObject c;
return 0;
}
Get this small utility to do basic syntax highlighting in vBulletin forums (like Codeguru) easily.
Supports C++ and VB out of the box, but can be configured for other languages.
-
October 13th, 2003, 09:16 AM
#9
Originally posted by Dave McLelland
That should work (works here).
Do a preprocessed listing to a file and see what is actually being produced.
Can you post the actual code from the function declaration to the line after the std::list?
Here it is :
void
CCalView::CalcRdvRectList(CList<CRdv, CRdv> &RdvList, CList<CRect, CRect> &RdvRectList)
{
std::list<rdv_t> RdvCtrlList;
std::list<std::list<rdv_t>> AllConflicts;
std::list<rdv_t> ConflictsList;
POSITION pos;
CWnd * pRdvCtrl = NULL;
CRdv Rdv;
rdv_t rdv;
// Body of the method here.
}
It chokes at the very first std::list usage with the error message given in previous posts. I have no idea how to get a preprocessed file in Visual C++. Can you enlighten me?
Cheers,
Maxime
-
October 13th, 2003, 09:17 AM
#10
std::list<std::list<rdv_t>> AllConflicts;
You are missing a space between the two ">". It should be:
Code:
std::list<std::list<rdv_t> > AllConflicts;
Get this small utility to do basic syntax highlighting in vBulletin forums (like Codeguru) easily.
Supports C++ and VB out of the box, but can be configured for other languages.
-
October 13th, 2003, 09:23 AM
#11
right click on the source file in the solution explorer window.
From the C/C++ entry select preprocessor.
Select either of the options from "Generate preprocessed file".
The resultant file will have the .i extension.
Search this for your CalcRdvRectList and see what it says.
Dave Mclelland.
-
October 13th, 2003, 09:23 AM
#12
Originally posted by Yves M
You are missing a space between the two ">". It should be:
Code:
std::list<std::list<rdv_t> > AllConflicts;
Ok, I added it, thanks. But the compiler still errors. It's actually choking before this line, at the first usage of std::list. I don't think that I'm already inside some namespace since I don't see any other "using namespace" declaration.
Cheers,
Maxime
-
October 13th, 2003, 09:32 AM
#13
Are you including any list.h inside of this file or the other headers that are included ?
Get this small utility to do basic syntax highlighting in vBulletin forums (like Codeguru) easily.
Supports C++ and VB out of the box, but can be configured for other languages.
-
October 13th, 2003, 09:40 AM
#14
Originally posted by Yves M
Are you including any list.h inside of this file or the other headers that are included ?
Yes, I am, or actually I was :-). I moved the "#include <list>" after the other #include directives and it's now working. There must have been something in those headers which was confusing stuff. Thanks a bunch for your help and the other members' help!
Cheers,
Maxime
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|