-6

I right now am making a multithreading library for lua, and everything would compile if there weren't this strange problem. I have a container object for holding the thread object class I created. Here is the header for this object:

 #include "stdafx.h"
    ;

using namespace std;
class LuaThreadManager {
public:  
    LuaThreadManager(int size);
    Thread& get(int id);
        int add(Thread& t);
void remove(int id);
protected: 
     vector <Thread&> T; 
     int numoccupied; 
}

When I compile, I get three errors from this header(I will note that they are all at the line where I declare my header):

Line 12: error C2143: syntax error : missing ';' before '<'

Line 12: error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

Line (12): error C2238: unexpected token(s) preceding ';'

And here is my question: what the heck am I doing wrong? (Also, you will see the identifier Thread in the vector declaration; it is my thread object I created) EDIT: All of the answers I have been given haven't worked. It isn't because I didn't include the vector library(I DID include it via including it in stdafx.h_, or because I am using references for the vector (fixed that, didn't fix my errors).

scrat101
  • 89
  • 1
  • 2
  • 8
  • Someone has to know an answer to this... – scrat101 Nov 25 '12 at 16:32
  • @scat101 add the following two lines in your code above, *after* including `stdafx`: (1) `#undef vector`, then (2) `#include `. If that works see which of the two lines made actually the difference. – vladr Nov 25 '12 at 17:14

3 Answers3

3

You're not including the <vector> header. :)

(Stylistically, another thing you're doing wrong is putting using namespace std in a header file. Don't do that)

jalf
  • 243,077
  • 51
  • 345
  • 550
  • I am including the vector header; it is in my stdafx header, which I include. – scrat101 Nov 25 '12 at 15:05
  • 3
    another thing he's doing wrong: vector of references. – ipc Nov 25 '12 at 15:05
  • what is wrong with a vector of references? – scrat101 Nov 25 '12 at 15:06
  • 5
    @scrat101: It's not possible, is the main flaw. – Lightness Races in Orbit Nov 25 '12 at 15:07
  • Why isn't it? Plus, how is that helping solve the problems(curious)? – scrat101 Nov 25 '12 at 15:09
  • 2
    Find it out yourself: [Why can't I make a vector of references?](http://stackoverflow.com/questions/922360/why-cant-i-make-a-vector-of-references). It's probably the next error you get if you have fixed your include. – ipc Nov 25 '12 at 15:11
  • One time, for the sake of curiousity, I tried a plain int type, no references, no nothing special, just the int type. Didn't fix my problem; it spat back the same errors. Plus, I tried pointers at first for my objects, but it said no conversion for such a thing existed. – scrat101 Nov 25 '12 at 15:14
  • Now I made a wrapper object around my reference object, so the vector should be happy now; at least in that respect. Still gives the same errors though. – scrat101 Nov 25 '12 at 15:27
3

std::vector cannot be specialized for reference types. The elements of a vector need to be assignable, which references are not.

The nearest equivalent may be a std::vector<std::reference_wrapper<Thread>>, depending on whether that suits your design.

Kerrek SB
  • 464,522
  • 92
  • 875
  • 1,084
  • I implemented a reference wrapper style implementation when people pointed that out, but it seems that it doesn't fix my current errors. – scrat101 Nov 25 '12 at 15:39
1

You have missed the terminator ; after the closing braces of your class LuaThreadManager

  • Come on, there has to be an answer to my problem. – scrat101 Nov 25 '12 at 16:27
  • 1
    @scrat101: Badgering people won't get you what you want. Don't be so impatient. Saurabh has pointed out an error you've made, and it could be just one of many errors. Fix this one, thank him, then look to see whether you've made the same error elsewhere. – Lightness Races in Orbit Nov 25 '12 at 17:01