Click here to Skip to main content
16,005,120 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Worker-Thread In Win32 Application Pin
Ravi Bhavnani20-Apr-03 12:09
professionalRavi Bhavnani20-Apr-03 12:09 
GeneralAdding controls to a ListView based app Pin
TelMonks20-Apr-03 4:01
TelMonks20-Apr-03 4:01 
GeneralRe: Adding controls to a ListView based app Pin
Ravi Bhavnani20-Apr-03 6:35
professionalRavi Bhavnani20-Apr-03 6:35 
GeneralRe: Adding controls to a ListView based app Pin
TelMonks20-Apr-03 7:59
TelMonks20-Apr-03 7:59 
GeneralMeeting troubles when reading two integers from a file. Pin
George220-Apr-03 2:41
George220-Apr-03 2:41 
GeneralRe: Meeting troubles when reading two integers from a file. Pin
Nick Parker20-Apr-03 3:15
protectorNick Parker20-Apr-03 3:15 
GeneralRe: Meeting troubles when reading two integers from a file. Pin
George220-Apr-03 3:23
George220-Apr-03 3:23 
QuestionHow to let vector store reference? Pin
George220-Apr-03 2:31
George220-Apr-03 2:31 
Hi, everyone!


When using vector.push_back method, we just copy an object
an not a reference. I think sometimes it is a waste. Am I
correct? I want to know how to let the vector to store
a reference.

Such is my sample code which can verify vector store copied
object and not reference.


Source Code:
--------
#include <vector>
#include <iostream>

using namespace std;

class A {

public:

int a;

};

int main()
{
A a;
a.a = 10;
vector<A> vc;
vc.push_back (a);
A b;
vector<A>::const_iterator i = vc.begin();
for (; i < vc.end(); i++)
{
b = *i;
b.a = 100;
}

cout << a.a << endl; //output is 10
return 1;
}
--------


So, how to let vector to store reference?


Thanks in advance,
George
AnswerRe: How to let vector store reference? Pin
Nick Parker20-Apr-03 3:22
protectorNick Parker20-Apr-03 3:22 
GeneralRe: How to let vector store reference? Pin
George220-Apr-03 3:27
George220-Apr-03 3:27 
GeneralRe: How to let vector store reference? Pin
Nitron21-Apr-03 3:09
Nitron21-Apr-03 3:09 
GeneralRe: How to let vector store reference? Pin
George221-Apr-03 19:52
George221-Apr-03 19:52 
GeneralRe: How to let vector store reference? Pin
Nitron22-Apr-03 2:51
Nitron22-Apr-03 2:51 
GeneralMacro Question / getting detailed Class / Functioncall Information Pin
Sendel20-Apr-03 1:39
Sendel20-Apr-03 1:39 
GeneralRe: Macro Question / getting detailed Class / Functioncall Information Pin
Phil Hamer20-Apr-03 7:26
Phil Hamer20-Apr-03 7:26 
GeneralRe: Macro Question / getting detailed Class / Functioncall Information Pin
Phil Hamer20-Apr-03 7:43
Phil Hamer20-Apr-03 7:43 
Questionhow to display a file into CScrollView? Pin
liuty200619-Apr-03 21:18
liuty200619-Apr-03 21:18 
AnswerRe: how to display a file into CScrollView? Pin
Nish Nishant19-Apr-03 21:24
sitebuilderNish Nishant19-Apr-03 21:24 
GeneralTraversing between workspaces Pin
Makover19-Apr-03 20:55
Makover19-Apr-03 20:55 
Generali'm new Pin
Mario_Young19-Apr-03 18:32
Mario_Young19-Apr-03 18:32 
GeneralRe: i'm new Pin
J. Dunlap19-Apr-03 18:37
J. Dunlap19-Apr-03 18:37 
GeneralRe: i'm new Pin
Nish Nishant19-Apr-03 19:24
sitebuilderNish Nishant19-Apr-03 19:24 
GeneralRe: i'm new Pin
Sendel20-Apr-03 1:53
Sendel20-Apr-03 1:53 
GeneralOption for an Exit Pin
Anonymous19-Apr-03 18:17
Anonymous19-Apr-03 18:17 
GeneralRe: Option for an Exit Pin
Bartosz Bien20-Apr-03 4:32
Bartosz Bien20-Apr-03 4:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.