Compiler Error: cannot convert 'Point' to 'char' in assignment

I'm having trouble understanding exactly what the error message "Error: cannot convert 'Point' to 'char' in assignment" is getting at. The error points to this particular line grid[i][j]= temp;.

This particular snippet is from grid.h where I declare the 2D vector.
std::vector< std::vector <Point> > grid;

This is the function in Grid.cpp where the error is occurring.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void Grid::generate_grid()
{
    srand(time(NULL));

    for(int i=0; i < height; i++)
        for(int j=0; j < width; j++)
        {
            Point temp;
            temp.letter=rand() % 25 + 65;
            temp.word_index=-1;
            grid[i][j]= temp;
        }

    return;
}


I'm very confused as to what this error message means as I've defined Point as a simple struct that holds a char and an int value. The code effectively broke for me when I attempted to change from using a 2D vector of chars to a 2D vector of Points. Google has unfortunately not been my friend in this endeavor.
i guess grid is a 2d char array. so grid[i][j] is a char.
point is a struct of char and int.

point and char are 2 different datatypes, so you can't save a point as char. i guess you just want to save the char value of the point struct, so use "." to get the char and then save it in grid[i][j].
Make clean build. Look into your IDE documentation to find out how.
Darkmaster it is my understanding that I have defined the 2D vector as a vector of a vector that holds the type Point. The 2D vector, which I've named grid, should be of the correct type to accept the Point type.

MiiNiPaa I looked up how to clean my project, and I rebuilt it from scratch. Unfortunately, the error persists.
oh, i somehow missed that line

but i don't see that working at all. your vector has no set size, so grid[i][j] doesn't exist yet.
what you need to use is pushpack.
Then the problem somewhere else, because your code should compile just fine:
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
#include <vector>
#include <cstdlib>
#include <ctime>

struct Point
{
    char letter;
    int word_index;
};

const int height = 10, width = 10;

std::vector< std::vector <Point> > grid;

void /*Grid::*/generate_grid()
{
    srand(time(NULL));
    for(int i=0; i < height; i++)
        for(int j=0; j < width; j++)
        {
            Point temp;
            temp.letter=rand() % 25 + 65;
            temp.word_index=-1;
            grid[i][j]= temp;
        }

    return;
}

int main() 
{
	return 0;
}

This code works for me.
As Darkmaster pointed out, your vectors are empty.

What about this?
1
2
3
4
5
6
7
8
9
10
11
12
void /*Grid::*/generate_grid()
{   for(int i=0; i < height; i++)
    {  vector<Point>    v;
       for(int j=0; j < width; j++)
       {  Point temp;
           temp.letter=rand() % 25 + 65;
           temp.word_index=-1;
           v.push_back (temp); 
       }
       grid.push_back(v);    
    }
}


BTW, your call to srand() should only occur in your program once. It's best if placed at the beginning of main.
MiiNiPaa was right and my IDE totally lied to me. The issue was that Code::Blocks was failing to clean a single object file and overwrite it during subsequent build attempts. The object file just happened to be the one holding the grid definition. It appears that particular object file was last modified two days ago. That is pretty much the time I changed the grid definition to another type. I became suspicious when MiiNiPaa's single file example compiled and a brand new project with identical code also compiled. I took a quick look in the source folder itself, and I could see that one file was being left behind in clean/build cycles. I manually deleted it, and the next build completed successfully.

I would like to thank you all very much for your time, solutions, and code suggestions. It was extremely frustrating as hours spent looking for a bug in the code was in vain as the source code itself wasn't bugged. I was unaware of the clean function beforehand, and once I became aware of its existence/function that put me on the right track. I also learned to never trust a button fully does what it advertises.
MiiNiPaa's code may compile, but it won't work. As Darkmaster and I both pointed out previously, your vectors are empty. You can't store something into grid[i][j] when i or j are greater than the number of entries in the respective vector (zero). You will get a run time exception.
Topic archived. No new replies allowed.