469,133 Members | 1,179 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,133 developers. It's quick & easy.

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 2138

"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
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.