Size of Array of Vectors in for loop


This is a portion of my code:

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
int charIs(char input) {
	vector <char> list[3] = {
			{'a', 'b', 'c'},
			{'d', 'e', 'f'},
			{'g', 'h', 'i'}
	};
	for (unsigned int i0 = 0; i0 < 3; i0++) {
		for (unsigned int i1 = 0; i1 < list[i0].size; i1++) {
			if (input == list[i0][i1]) {
				return i0;
			};
		};
	};
	return (unsigned int)4;
};


If I write this:
charIs('a');
Then I would expect the function to return the number 0.

These are the errors shown in Visual Studio 2019 (Both are for line 17):


Error	C3867	'std::vector<char,std::allocator<char>>::size': non-standard syntax; use '&' to create a pointer to member

Error	C2446	'<': no conversion from 'unsigned int (__thiscall std::vector<char,std::allocator<char>>::* )(void) noexcept const' to 'uint'


How do I fix these errors while keeping the intended design of the code?
Last edited on
How about replacing this:
vector <char> list[3]

with:
vector <char[3]> list

At least I think that should be possible.
That did not work unfortunately

I receive these errors when I do that:

E0289	no instance of constructor "std::vector<_Ty, _Alloc>::vector [with _Ty=char [3], _Alloc=std::allocator<char [3]>]" matches the argument list

E0153	expression must have class type

C2440	'initializing': cannot convert from 'initializer list' to 'std::vector<char [3],std::allocator<_Ty>>'
You need to use list[i0].size() instead of list[i0].size

:)
This should work:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
	int charIs(char input)
	{
		std::vector<std::array<char, 3>> list{
				{'a', 'b', 'c'},
				{'d', 'e', 'f'},
				{'g', 'h', 'i'}
		};

		for (unsigned int i0 = 0; i0 < 3; i0++)
		{
			for (unsigned int i1 = 0; i1 < list.at(i0).size(); i1++)
			{
				if (input == list[i0][i1])
				{
					return i0;
				};
			};
		};

		return (unsigned int)4;
	};
Topic archived. No new replies allowed.