Welcome, Guest. Please login or register.

Author Topic: GCC:C++:STL:vector  (Read 6487 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: GCC:C++:STL:vector
« on: April 01, 2003, 01:30:40 PM »
Youre getting a lot of C++ iostream references. The STL uses IO streams for IO in preference to the C IO style methods. My guess is that you're getting problems caused by unreferenced calls to IO stream code.

Try adding

#include

Also, you commented out everything that uses your vector - it may get optimised away...

Hope this helps.
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: GCC:C++:STL:vector
« Reply #1 on: April 01, 2003, 01:45:30 PM »
Quote

Rodney wrote:

Incase you cant tell from the program, im trying to find out if when adding an element to a vector, does the vector simply copy the element past into push_back() and put it in the vector, or does it obtain the objects address and add the reference in the vector?



Well, that depends on what you create a vector of. A template uses whatever T is given to it, be it a class, integer, float, int* you name it.
Internally, most vector implementations use something like a conventional array (the kind you get with operator new[]).

Getting back to our template stuff,  a vector is a vector of ints.

Similarly,

class Dummy {
  int a, b, c;
  float x, y, z;
...
}

vector is a vector of Dummy objects.

Assignment etc. would be done via a user-defined copy constructor if defined, or the default copy constructor if it isnt. For ints and other elemental types, copying is of the straightforward a = b; assignment type.

Beware of default copy construction in classes that have dynamically allocated data inside! You really need to take charge on how these things are copied yourself by providing a copy constructor.

Also, if you make the your copy constructor for your Dummy class private or protected you probably wouldn't be able to make a vector of it.

Moving on, if you want a vector of references, you need to do it something like this

vector

Or alternatively create a class which is a wrapper for a Dummy* and use a vector of that.

Anyhoo, hope this answers a your question a bit.
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: GCC:C++:STL:vector
« Reply #2 on: April 01, 2003, 02:18:53 PM »
Hmm,

Well the whole headername / headername.h thing is fairly recent in C++. According to the current standards, the .h part of the name is redundant (the compiler knows you're talking about a header). However, the .h should still work fine. Personally when I write my headers I stick to .hpp ;-)

As for your woes, I guess there may be a problem at the linker stage. After I posted the iostream thing I realised that it wouldn't really matter - the STL components that use IO stream would include it themselves. Since your main file isn't using any iostream stuff, things should be ok even though you didn't include it there.

My guess is that somehow your installation is broken - some .lib files may be missing or the compiler is somehow looking in the wron place for them.

Unfortunatley, I recently had to flatten my developer partition :-( so I need to go the the whole install/build hassle again...
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: GCC:C++:STL:vector
« Reply #3 on: April 03, 2003, 09:56:26 AM »
@Anybody

What's the current gcc WarpOS build ?

Cheers
int p; // A