a stupid question

Discussion in 'C++' started by C++ Shark, Jun 25, 2003.

  1. C++ Shark

    C++ Shark Guest

    Hi, the following doesn't compile.

    #include<iostream>
    #include<vector>
    using namespace std;
    class tile_type {
    vector<vector<int> > grid(3, vector<int> (3));
    public:

    };
    int main()
    {
    tile_type k;

    return 0;
    }

    The compiler (g++) says:

    tile.cpp:5: invalid data member initialization
    tile.cpp:5: (use `=' to initialize static data members)
    make: *** [tile] Error 1

    I am trying to make an object with an array, so that I can access
    k.grid[][]. I am using Dietel & Dietel's book, and though I looked it
    over, I couldn't find a right way of doing this type of thing. I hope
    you can tell me the correct method.

    thanking you,
    Craig.
     
    C++ Shark, Jun 25, 2003
    #1
    1. Advertising

  2. C++ Shark

    tom_usenet Guest

    On 25 Jun 2003 09:46:13 -0700, (C++ Shark) wrote:

    >Hi, the following doesn't compile.
    >
    >#include<iostream>
    >#include<vector>
    >using namespace std;
    >class tile_type {
    > vector<vector<int> > grid(3, vector<int> (3));
    > public:


    You can only initialize non-static members in a constructor
    initializer list. So you want:

    vector<vector<int> > grid;
    public:
    tile_type(): grid(3, vector<int>(3))
    // comma delimit initializers for other members
    // and base classes
    {
    }

    Tom
     
    tom_usenet, Jun 25, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Michael W Cocke

    Stupid RE question

    Michael W Cocke, Dec 27, 2004, in forum: Perl
    Replies:
    2
    Views:
    442
    Michael W Cocke
    Dec 28, 2004
  2. Steve

    Is this a stupid question?

    Steve, Jul 17, 2003, in forum: ASP .Net
    Replies:
    6
    Views:
    358
    Mario Vargas
    Jul 17, 2003
  3. Will

    Stupid C# question Please help!

    Will, Aug 8, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    454
    carlos medina
    Aug 9, 2003
  4. Brandon McCombs
    Replies:
    4
    Views:
    525
    Richard Wheeldon
    Aug 28, 2006
  5. rincewind

    stupid, STUPID question!

    rincewind, Apr 19, 2009, in forum: HTML
    Replies:
    25
    Views:
    1,040
Loading...

Share This Page