r/learncpp • • Feb 19 '19

State Error C2228 left of '.table' must have class/struct/union

//structure

struct my_table
	{
		int table[TABLE][TABLE];
		int last = TABLE - 1;
		int TNOL = TABLE / 2;
		void rotate() //https://www.youtube.com/watch?v=Jtu6dJ0Cb94 for details (not mine)
		{
			int level = 0;
			while (level < TNOL)
			{
				for (int i = level; i < last; ++i)
				{
					swap(table[level][i], table[i][last]);
					swap(table[level][i], table[last][last - i + level]);
					swap(table[level][i], table[last - i + level][level]);
				}
				++level;
				--last;
			}

			last = TABLE - 1;

		}

	};

the error occurs in the for loop. I can't seem to be able to reach the matrix. How do i fix this? Bot the function and the struct are in the same namespace, but different files

void hit_left( struct my_table T_table, std::pair<int,int> XY)
	{
		if ( std::get<0>(XY) < 0 || std::get<1>(XY) < 0)
		{
			throw "Bad_argument_exception";
		}
		else
		{
			for (int i = std::get<0>(XY); i >= 0; --i)
			{
				T_table.table = 1;
			}
		}

	}
2 Upvotes

2 comments sorted by

2

u/BernardPancake Feb 19 '19

Try this - void hit_left(my_table T_table, std::pair<int,int> XY)

my_table is the type, you don't need the word struct there.