Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 779331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T19:54:48+00:00 2026-05-14T19:54:48+00:00

Yet another Scrabble project question… This is a simple one. It seems I am

  • 0

Yet another Scrabble project question… This is a simple one.

It seems I am having trouble getting my global constants recognized:

My board.h:
http://pastebin.com/7a5Uyvb8

Errors returned:

1>C:\Users\Francisco\Documents\FEUP\1A2S\PROG\projecto3\projecto3\Board.h(34): error:     variable "TOTAL_ROWS" is not a type name
1>      vector< vector<Cell> > _matrix(TOTAL_ROWS , vector<Cell>(TOTAL_COLUMNS));
1>
1>main.cpp
1>compilation aborted for .\Game.cpp (code 2)
1>Board.cpp
1>.\Board.h(34): error: variable "TOTAL_ROWS" is not a type name
1>      vector< vector<Cell> > _matrix(TOTAL_ROWS , vector<Cell>(TOTAL_COLUMNS));
1>                                     ^
1>

Why does this happen? Why is the compiler expecting types?

Thanks for your time!

EDIT:

Disregard my previous edit…
This is my default constructor:
Board::Board()
{
_matrix(TOTAL_ROWS, vector(TOTAL_COLUMNS));
}

I get the following error.

1>.\Board.cpp(16): error: call of an object of a class type without appropriate operator() or conversion functions to pointer-to-function type
1>       _matrix(TOTAL_ROWS, vector<Cell>(TOTAL_COLUMNS));
1>       ^

Why does this happen?


I managed to solve all the problems with my file. I used

Board::Board() :
     _matrix(TOTAL_ROWS, vector<Cell>(TOTAL_COLUMNS))
     {}

instead. Thanks for all your help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T19:54:48+00:00Added an answer on May 14, 2026 at 7:54 pm

    The way that is written, you are defining a function called _matrix that returns a vector. So TOTAL_ROWS is expected to be a type name, since it is being parsed as a paramter type. I assume what you are trying to do is define a variable called _matrix that is a vector.

    What you want to do is leave off the constructor, and initialize the variable inside your constructor. Only constant integral values can be initialized in the body of the class, at least in the current version of the standard.

    Leaving off the unimportant parts:

      Board() : _matrix(TOTAL_ROWS, vector<Cell>(TOTAL_COLUMNS)) { }
    
    private:
      vector< vector<Cell> > _matrix;
    

    Note that this is just an example. Presumably you have an implementation file with an actual body for Board(), and you should put the initialization there rather than directly in the header or you’ll get errors. The important thing is that you should not do it when you declare _matrix initially.


    For your new question, extern const unsigned int TOTAL_COLUMNS = 15; defines TOTAL_COLUMNS every time Board.h is included by a file. Constant variables at namespace scope have internal linkage by default, so if you leave off the extern you will be okay.

    In general, if the variable isn’t constant, you take an approach similar to the one for _matrix. You leave off the initialization in the header, and then inside an implemenation file put it back on:

    board.h:
    extern const int TOTAL_COLUMNS;

    board.cpp:
    extern const int TOTAL_COLUMNS = 15;

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Back again with yet another DirectSound question, this one regarding the ways DirectSound Buffers
I guess this question will sound familiar, but I am yet another programmer baffled
Yet another one of my idiotic P/Invoke questions... Sometimes I think this stuff is
Yet another IE is doing something different from other browsers question but this is
this is yet another .htaccess question. And I already did my literature review. Would
Yet another one of my P/Invoke questions! I have this C function: int _ei_x_new(ei_x_buff*
This is yet another Unit Testing question. I'm trying to draw knowledge from a
This is yet another EXC_BAD_ACCESS question. Although I've done my homework and am certain
This is not yet another question about the difference between abstract classes and interfaces,
I'm having yet another WPF binding issue. Just when I think I've got this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.