Language: C++

#include<iostream>
#include<queue>
using namespace std;
struct data
{
	int x;
	int y;
};
struct mapData
{
	int black = 0;
	int white = 0;
};
int main()
{
	int w, h;
	int dx[4] = {1,0,-1,0};
	int dy[4] = {0,1,0,-1};
	while (cin >> w >> h && w != 0 || h != 0)
	{
		char map[50][50];
		for (int i = 0; i < h; i++)
		{
			cin >> map[i];
		}

		mapData whiteBlack[50][50];
		for (int i = 0; i < h; i++)
		{
			for (int j = 0; j < w; j++)
			{
				whiteBlack[i][j].black = 0;
				whiteBlack[i][j].white = 0;
			}
		}

		for (int i = 0; i < h; i++)
		{
			for (int j = 0; j < w; j++)
			{
				if (map[i][j] == '.')continue;
				int color = (map[i][j] == 'B' ? 1 : 2);
				queue<data> q;
				data first;
				first.x = j;
				first.y = i;
				q.push(first);
				while (q.size() > 0)
				{
					data d = q.front(); q.pop();
					if (map[d.y][d.x] == '.')
					{
						if (color == 1)
						{
							whiteBlack[d.y][d.x].black = 1;
						}
						else
						{
							whiteBlack[d.y][d.x].white = 1;
						}
					}
					for (int k = 0; k < 4; k++)
					{
						int nx = dx[k] + d.x;
						int ny = dy[k] + d.y;
						if (nx >= w || ny >= h || nx < 0 || ny < 0)continue;
						if (map[ny][nx] == 'W' || map[ny][nx] == 'B')continue;
						if (color == 1 && whiteBlack[ny][nx].black == 1)continue;
						if (color == 2 && whiteBlack[ny][nx].white == 1)continue;
						data add;
						add.x = nx;
						add.y = ny;
						q.push(add);
					}
				}
			}
		}
		int white = 0;
		int black = 0;
		for (int i = 0; i < h; i++)
		{
			for (int j = 0; j < w; j++)
			{
				if (whiteBlack[i][j].black == 1 && whiteBlack[i][j].white == 0)
				{
					black++;
				}
				else if (whiteBlack[i][j].white == 1 && whiteBlack[i][j].black == 0)
				{
					white++;
				}
			}
		}

		cout << black << " " << white << endl;
	}
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:43:43: error: template argument 1 is invalid
   43 |                                 queue<data> q;
      |                                           ^
a.cc:43:43: error: template argument 2 is invalid
a.cc:44:33: error: reference to 'data' is ambiguous
   44 |                                 data first;
      |                                 ^~~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:4:8: note:                 'struct data'
    4 | struct data
      |        ^~~~
a.cc:45:33: error: 'first' was not declared in this scope
   45 |                                 first.x = j;
      |                                 ^~~~~
a.cc:47:35: error: request for member 'push' in 'q', which is of non-class type 'int'
   47 |                                 q.push(first);
      |                                   ^~~~
a.cc:48:42: error: request for member 'size' in 'q', which is of non-class type 'int'
   48 |                                 while (q.size() > 0)
      |                                          ^~~~
a.cc:50:41: error: reference to 'data' is ambiguous
   50 |                                         data d = q.front(); q.pop();
      |                                         ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:4:8: note:                 'struct data'
    4 | struct data
      |        ^~~~
a.cc:50:63: error: request for member 'pop' in 'q', which is of non-class type 'int'
   50 |                                         data d = q.front(); q.pop();
      |                                                               ^~~
a.cc:51:49: error: 'd' was not declared in this scope
   51 |                                         if (map[d.y][d.x] == '.')
      |                                                 ^
a.cc:64:66: error: 'd' was not declared in this scope
   64 |                                                 int nx = dx[k] + d.x;
      |                                                                  ^
a.cc:70:49: error: reference to 'data' is ambiguous
   70 |                                                 data add;
      |                                                 ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:4:8: note:                 'struct data'
    4 | struct data
      |        ^~~~
a.cc:71:49: error: 'add' was not declared in this scope
   71 |                                                 add.x = nx;
      |                                                 ^~~
a.cc:73:51: error: request for member 'push' in 'q', which is of non-class type 'int'
   73 |                                                 q.push(add);
      |                                                   ^~~~