-
Errors from STL
Like the title says, when I try to compile my program, I get errors from inside the list.h code, for the list STL. Here is the code in question:
#include<stdlib.h>
#include<stdio.h>
#include<iostream.h>
#include<list.h>
#include "Event.h"
#include "main.h"
int main(void)
{
float simulated_time = 0;
Event event_1(40, .23);
Event event_2(45, .45);
if(event_1.get_arrival_time() > simulated_time)
simulated_time = event_1.get_arrival_time();
list<Event> ReadyList;
ReadyList.push_front(event_1);
}
void cause(char event, Event thisEvent, float TimeEvent)
{
if(event == 'a')
ReadyList.push_front(thisEvent);
}
I'm using msvc++. These are the errors I recieve:
Compiling...
main.cpp
c:\program files\microsoft visual studio\vc98\include\list.h(37) : error C2146: syntax error : missing ';' before identifier 'Length'
c:\program files\microsoft visual studio\vc98\include\list.h(37) : error C2501: 'DWORD' : missing storage-class or type specifiers
c:\program files\microsoft visual studio\vc98\include\list.h(37) : error C2501: 'Length' : missing storage-class or type specifiers
c:\program files\microsoft visual studio\vc98\include\list.h(53) : error C2146: syntax error : missing ';' before identifier 'GetPrevLink'
c:\program files\microsoft visual studio\vc98\include\list.h(53) : error C2433: 'WINAPI' : 'inline' not permitted on data declarations
c:\program files\microsoft visual studio\vc98\include\list.h(53) : fatal error C1004: unexpected end of file found
Error executing cl.exe.
TIA
-
I see that you don't use the std namespace, which I think is good practice. But you must not forget to use the std:: then!
Code:
std::list<Event> ReadyList;
I'm really not sure if this will solve your problem, but thats the only fault I see. Except some bad programming practice. ;)
Code:
// this is bad looking code:
if(event_1.get_arrival_time() > simulated_time)
simulated_time = event_1.get_arrival_time();
//either do this:
if(event_1.get_arrival_time() > simulated_time) simulated_time = event_1.get_arrival_time();
//or this: <- I prefer to do this.
if(event_1.get_arrival_time() > simulated_time){
simulated_time = event_1.get_arrival_time();
}
It's the same code only looks different. Why do this? Easier to read, you won't missinterpritate the statement. This is otherwise a common bug place, just because you read the statement the wrong way. Look at this:
[code]
Code:
// this time I add another thing to the if statement:
if(event_1.get_arrival_time() > simulated_time)
simulated_time = event_1.get_arrival_time();
simulated_time += TIME_CONSTANT;
//OPS! error because I wanted the time_constant to be added to the simulated time if the ifstatement was true. And this bug only because I forgot the braces in the first place. If they were there from the beginning I wouldn't have missed them.
Well you get the idea: get it right the first time.
Tip:
Also i'm not sure abou the stl-list, but generally there are different insert time for push_front and push_back function. If i'm not totally lost right now, the push_back is faster than the front version. Do i performance check on the two and see. It might as well be the pop_front - pop_back that differs in time.
Well enough ranting ;)
-
Ok, if I wanted a lesson in how to write C, I would have asked for it. :rolleyes: Now, does anyone know why I'm getting these errors?
-
I believe you have to use:
#include <list>
without the .h if you are using list class from STL. If that is the case, then I you may also need to drop the .h extension from the other indluded files and use a namespace like this:
using namespace std;
in the global name space or use namespace specifiers as in the previous post.
I do not usually use main.h in my list of includes, but I'm not sure if listing it will create an error.
-
some of those errors could be in the class header you should post it too