Hi,
I have some questions on vector.
Please consider the code below. I use g++ compiler on Linux.
#include<iostream>
#include<vector>
using namespace std;
class Sampler {
int a;
int b;
};
int main()
{
vector <int> vec1;
vector<float> vec2;
vector<Sampler> vec3;
cout << sizeof(vec1) << " " << sizeof(vec2)
<< sizeof(vec3) << endl;
return 0;
}
1. when I try sizeof() with vector objects of different types, the size is shown as 12 bytes. What surprises me even further is, even after pushing an element in to the vector, sizeof shows the same size.
Could somebody please explain why? Does the compiler not discriminate the type of data a vector holds?
2. In the above code snippet, when I define class Sampler as a local class, g++ shoots an error. Why is it that compiler works fine with vector vec3's declaration when class Sampler is global and shoots an error when Sampler is local to main?
Thanks in advance.