I
Ioannis Vranos
The code:
#include <iostream>
#include <ctime>
#include <vector>
#include <cstddef>
struct SomeClass
{
typedef std::vector<int> TypeVector;
TypeVector vec;
enum { VectorSize= 10 };
public:
SomeClass();
};
SomeClass::SomeClass():vec(VectorSize)
{
using namespace std;
for(TypeVector::size_type i= 0; i< vec.size(); ++i)
{
vec= rand();
cout<<vec<<" ";
}
cout<<"\n\n";
}
int main()
{
using namespace std;
srand(time(0));
const size_t SIZE=10;
typedef vector<SomeClass> Vector;
cout<< "\nCreating vector with "<< SIZE<< " SomeClass objects..."<<
endl;
Vector vec(SIZE);
}
in my system produces:
john@john-desktop:~/Projects/Other/anjuta1/src$ ./foobar_cpp
Creating vector with 10 SomeClass objects...
73703028 1208935909 602693459 1501639085 1773871829 541492682
713359358 1018154590 823363404 280191048
john@john-desktop:~/Projects/Other/anjuta1/src$
(10 values) instead of 100 values. Is it a compiler defect, or am I
missing something?
#include <iostream>
#include <ctime>
#include <vector>
#include <cstddef>
struct SomeClass
{
typedef std::vector<int> TypeVector;
TypeVector vec;
enum { VectorSize= 10 };
public:
SomeClass();
};
SomeClass::SomeClass():vec(VectorSize)
{
using namespace std;
for(TypeVector::size_type i= 0; i< vec.size(); ++i)
{
vec= rand();
cout<<vec<<" ";
}
cout<<"\n\n";
}
int main()
{
using namespace std;
srand(time(0));
const size_t SIZE=10;
typedef vector<SomeClass> Vector;
cout<< "\nCreating vector with "<< SIZE<< " SomeClass objects..."<<
endl;
Vector vec(SIZE);
}
in my system produces:
john@john-desktop:~/Projects/Other/anjuta1/src$ ./foobar_cpp
Creating vector with 10 SomeClass objects...
73703028 1208935909 602693459 1501639085 1773871829 541492682
713359358 1018154590 823363404 280191048
john@john-desktop:~/Projects/Other/anjuta1/src$
(10 values) instead of 100 values. Is it a compiler defect, or am I
missing something?