Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Sepples Magic

Name: Anonymous 2011-02-23 21:22


#include <string>
#include <vector>
#include <iostream>

std::vector<std::string> names;

void addNames()
{
    names.push_back(std::string("Foo"));
    names.push_back(std::string("Bar"));
}

int main(int argc, char **argv)
{
    addNames();
   
    for (int i = 0, size = names.size(); i < size; ++i)
    {
        std::cout << names[i] << std::endl;
    }

    return 0;
}


Output:

Foo
Bar


Okay so what I'm trying to understand is since I'm pushing anonymous stack string objects onto the vector, I'm assuming that the strings will also have their destructors called (because local variables). This should also destroy the internal char sequence.

Yet the strings remain intact when printing the vector (so somehow its being copied?). So /prog/ please show me your sepples mastery and explain the magic here.

Name: Anonymous 2011-02-23 21:25

>>1
Are you familiar with C? If yes, remember that classes are just structs whose members are private by default.

Name: Anonymous 2011-02-23 22:02

This thread has been closed and replaced with the following thread:

Subject: U MENA HASKAL MUZIK
Name:
Email:

It works.http://yaxu.org/category/text/

Name: Anonymous 2011-02-23 22:05

>>3
Male Haskellsexual detected.

Name: >>3 2011-02-23 22:13

>>4
Your thinger's broken.

Name: Anonymous 2011-02-23 23:41

>>1
Fuck you faggot.

Name: Anonymous 2011-02-24 5:38

>>1
Okay so what I'm trying to understand is since I'm pushing anonymous stack string objects onto the vector,

You are pushing copies of them actually. Which use copies of the string constants themselves. In other words: you have a char* constant "Foo" allocated in the program's const data area, a temporary stack-allocated string object and a heap region containing the copy of "Foo", and an element of a vector<string> holding a pointer to another heap region containing the copy of "Foo". The destruction of the temporary doesn't affect either of the others.

You now also see how C++ allows utilizing every last bit of performance of the hardware!

Name: Anonymous 2011-02-24 6:00

>>7
-funroll-constants

Name: Anonymous 2011-02-24 6:13

Name: Anonymous 2011-02-24 6:39

>>
"There are so many steps involved in tweaking the last uumph out of your linux system- and it really is a work of art to pull it off- I have used many different kernels and all sorts of optimization combinations-yesterday I finally used -noatime and -notail for my reiserfs file system: The single biggest performance boost I have yet to see-now I can have gnome2.2 running using gnome-terminal to compile the latest j2sdk from source (nice -n 19)while browsing with mozilla while running e17 in a seperate login with two eterms and run Unreal Tournament at full speed (this with an apache webserver running for my dyndns pseudo-domain and a mysql for my answering-machine software for my isdn card-which keeps track of all incomming phonecalls and manages my telephone book app and ntfsd/sshd/dhcp server/squid)..."
VROOM!! VROOOM!!!!

Name: Anonymous 2011-02-24 7:48

C++ is an abomination. Do not user it ever!!! But importantly check my dubs

Name: Anonymous 2011-02-24 8:13

>>11
DUBZ JUST KICKED IN YO
VROOOOOOOOOMVROOOOOOOOM

Name: Anonymous 2011-02-24 8:29

FIBONACCIBUTTSORT

Name: Anonymous 2011-02-24 8:45

>>13
YOUR FIBONACCI BUTTSORTER BREAKS ON SPACES

Name: Anonymous 2011-02-24 12:27

<-- check it. epic binary quads (0b1111)

Name: Anonymous 2011-02-24 13:41

2^2^2

Name: Anonymous 2011-02-24 14:33

23+32 GET

Name: Anonymous 2011-02-24 14:36

>>14
There never were any

Name: Anonymous 2011-02-25 1:41

class B address subnet mask GET

Name: Anonymous 2011-02-25 2:29

>>19 That would be CIDR netblock GET
Much as this is a a /20 netblock GET; that's a s/n mask of 255.255.240.0; with 4094 usable hosts...
Also sage

Name: Anonymous 2011-02-25 7:23

<---- epic almost-dubz checkem

Name: Anonymous 2011-02-25 7:27

[m]vjrvk ,y find

Name: Anonymous 2011-02-25 7:28

>>20
you know what I meant though, and it's not as if I could really have a 255.255.224.0 GET

enjoy your autism

no sage

Name: Anonymous 2011-02-25 7:32

>>10,12

Honk-honk.

Honk-honk.

Honk-honk.

It's Chen time :3

Name: Anonymous 2011-02-25 7:34

<--- epic singles checkem

Name: Anonymous 2011-02-25 9:16

IIRC, passing anonymous stack objects as method/function arguments has different semantics from passing named stack objects.

The former would result in a call to the following method and the anonymous string object would actually be the named argument, as opposed to being copied into it (only one object would be created):
void std::vector<std::string>::push_back(string str);

While the latter result in a call to this method:
void std::vector<std::string>::push_back(const string &str);

Name: Anonymous 2011-02-25 9:53

IIRC, passing anonymous stack objects as method/function arguments has different semantics from passing named stack objects.
Sounds like bullshit to me. http://www.google.com/url?sa=t&source=web&cd=1&ved=0CBMQFjAA&url=http%3A%2F%2Fopenassist.googlecode.com%2Ffiles%2FC%252B%252B%2520Standard%2520-%2520ANSI%2520ISO%2520IEC%252014882%25202003.pdf&ei=6MFnTdHXHsqcOuSZrZIL&usg=AFQjCNG4-cbawIu_O0_KwFqjXU6VG1cZDA -- here's the C++ 2003 standard, please try finding the confirmation of your words.

Name: Anonymous 2011-02-25 10:01

>>27
Nah, I'm OK if what I said was wrong. As I said, it's possible I'm not remembering it correctly. You're welcome to look for confirmation/refutation yourself, though.

Name: Anonymous 2011-02-25 11:23

Name: Anonymous 2011-02-25 13:25

<-------- epic round number checkem

Don't change these.
Name: Email:
Entire Thread Thread List