Compiler error: "expected identifier before numeric constant"

I am getting "error: expected identifier before numeric constant" at line 8 of some code. Line 8 doesn't have any numeric constants (just a class declaration) so I have no clue what the error means.

1
2
3
4
...
class 2dvector
{
...
I think there is a mistake with the code you put on here. Try re-posting with all of your source code and the error message.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#ifndef INCLUDE_2DVECTOR
#define INCLUDE_2DVECTOR

#include <vector>

template <typename T>
class 2dvector
{
private:
    std::vector<T> data;
    unsigned wd, ht;

public:
    unsigned width() const { return wd; }
    unsigned height() const { return ht; }

    const T& operator () (unsigned x, unsigned y) const { return data[(y*wd)+x]; }
    T& operator () (unsigned x, unsigned y) { return data[(y*wd)+x]; }

    void resize(unsigned w, unsigned h)
    {
        data.resize(w*h);
        wd = w;
        ht = h;
    }

    2dvector() : wd(0), ht(0) { }

    2dvector(unsigned x, unsigned y)
        : wd(x), ht(y)
        , data(x*y, val)
    { }
};

#endif 


Its line 7 now, not 8.
Last edited on
An identifier must begun with either a letter or underscore. 2dvector is not a valid name as it begins with a digit.
closed account (j3Rz8vqX)
Your class name cannot start with a numeric value:
class 2dvector


Call it something else.
Oh, OK. I must have glossed over that in the tutorial
Topic archived. No new replies allowed.