471,607 Members | 1,776 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,607 software developers and data experts.

vector<int> and vector<bool>

------ 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 `&'

-------------------
Why can't we get a pointer to the first element of vector<bool> ?

--
Alex Vinokur
email: alex DOT vinokur AT gmail DOT com
http://mathforum.org/library/view/10978.html
http://sourceforge.net/users/alexvn


Jul 22 '05 #1
1 2260

"Alex Vinokur" <al****@big-foot.com> wrote in message
------ 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 `&'

-------------------
Why can't we get a pointer to the first element of vector<bool> ?


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

Sharad


Jul 22 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Scott Brady Drummonds | last post: by
3 posts views Thread by klaas | last post: by
6 posts views Thread by Alexandros | last post: by
3 posts views Thread by Alexandros | last post: by
4 posts views Thread by Jeff Paciga | last post: by
6 posts views Thread by zl2k | last post: by
reply views Thread by MichaelMortimer | last post: by
reply views Thread by CCCYYYY | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.