vector<int> and vector<bool>

A

Alex Vinokur

------ foo.cpp ------
#include <vector>
using namespace std;

int main()
{
const vector<int> v1 (10);
const vector<bool> v2 (10);

&v1[0];
&v2[0]; // Line#10

return 0;
}
---------------------

--- Compilation ---

// g++ 3.3.3

$ g++ -W -Wall foo.cpp
foo.cpp: In function `int main()':
foo.cpp:10: error: non-lvalue in unary `&'
 
S

Sharad Kala

Alex Vinokur said:
------ foo.cpp ------
#include <vector>
using namespace std;

int main()
{
const vector<int> v1 (10);
const vector<bool> v2 (10);

&v1[0];
&v2[0]; // Line#10

return 0;
}
---------------------

--- Compilation ---

// g++ 3.3.3

$ g++ -W -Wall foo.cpp
foo.cpp: In function `int main()':
foo.cpp:10: error: non-lvalue in unary `&'

vector<bool> is not a container and it does not contain bools. Read this -
http://www.gotw.ca/publications/mill09.htm

Sharad
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top