Strange behaviour

Discussion in 'C++' started by Ioannis Vranos, Oct 2, 2008.

  1. 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;

    srand(time(0));

    for(TypeVector::size_type i= 0; i< vec.size(); ++i)
    {
    vec= rand();

    cout<<vec<<" ";
    }

    cout<<"\n\n";
    }



    int main()
    {
    using namespace std;

    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...
    721719660 2021996343 352419231 1918327853 2096709369 504143813
    1554377841 1136725920 697167326 165934869

    john@john-desktop:~/Projects/Other/anjuta1/src$




    (10 values) instead of 100 values. Is it a compiler defect, or am I
    missing something?
     
    Ioannis Vranos, Oct 2, 2008
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Antonio

    Strange encoding behaviour

    Antonio, Dec 29, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    429
    Antonio
    Dec 29, 2004
  2. Jan
    Replies:
    2
    Views:
    1,446
    Mike Treseler
    Dec 16, 2004
  3. David Cantin

    Strange behaviour with perl and apache

    David Cantin, Nov 3, 2003, in forum: Perl
    Replies:
    1
    Views:
    456
    Jim Gibson
    Nov 3, 2003
  4. Dennis Johansson
    Replies:
    1
    Views:
    500
    Dennis Johansson
    Aug 21, 2003
  5. Andy Chambers
    Replies:
    1
    Views:
    393
    Daniel Dyer
    May 14, 2007
Loading...

Share This Page