Click here to Skip to main content
15,886,689 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: VS2010 Release Build Prob Pin
Sivaraman Dhamodharan8-Oct-12 22:42
Sivaraman Dhamodharan8-Oct-12 22:42 
GeneralRe: VS2010 Release Build Prob Pin
002comp10-Oct-12 0:07
002comp10-Oct-12 0:07 
QuestionSending iterator items to other functions from in a for block.... Pin
Ben Aldhouse8-Oct-12 21:32
Ben Aldhouse8-Oct-12 21:32 
QuestionRe: Sending iterator items to other functions from in a for block.... Pin
Maximilien9-Oct-12 3:53
Maximilien9-Oct-12 3:53 
AnswerRe: Sending iterator items to other functions from in a for block.... Pin
Ben Aldhouse9-Oct-12 10:16
Ben Aldhouse9-Oct-12 10:16 
GeneralRe: Sending iterator items to other functions from in a for block.... Pin
Stefan_Lang15-Oct-12 22:33
Stefan_Lang15-Oct-12 22:33 
GeneralRe: Sending iterator items to other functions from in a for block.... Pin
Ben Aldhouse16-Oct-12 21:35
Ben Aldhouse16-Oct-12 21:35 
GeneralRe: Sending iterator items to other functions from in a for block.... Pin
Stefan_Lang16-Oct-12 22:20
Stefan_Lang16-Oct-12 22:20 
You didn't use an actual iterator anywhere in the code that you posted, so I don't see the problem. When a function argument is declared as a reference, you can just pass a vector element, such as sliderVector[id]. If you do have an iterator, then you can just dereference it to get the vector element and pass that instead. If you wish to pass a pointer instead, just use the 'address-of' operator:
C++
void bar_ref(double& element) {
   element *= 2.0;
}
void bar_ptr(double* p_element) {
   *p_element += 3.0;
}
void foo() {
   std::vector<double> myvec(2); // size = 2
   myvec[0] = 3.1415;
   myvec[1] = 2.718;
   for (std::size_t i = 0; i < myvec.size(); ++i) {
      bar_ref(myvec[i]); // passing element by reference
      bar_ptr(&(myvec[i])); // passing element by pointer
   }
   for (auto it = myvec.begin(); it != myvec.end(); ++it) {
      bar_ref(*it); // passing vector element by reference from iterator
      bar_ptr(&(*it)); // passing vector element by pointer from iterator
   }
}

The only possible trap I see is trying to pass an iterator directly when a pointer is expected. An iterator may behave like a pointer, but, while - depending on the implementation - it may actually auto-convert to a valid pointer (I know VS 2003 did that), you shouldn't rely on that. (e. g. VS2010 doesn't accept it)
GeneralRe: Sending iterator items to other functions from in a for block.... Pin
Ben Aldhouse18-Oct-12 9:16
Ben Aldhouse18-Oct-12 9:16 
GeneralRe: Sending iterator items to other functions from in a for block.... Pin
Ben Aldhouse12-Nov-12 21:47
Ben Aldhouse12-Nov-12 21:47 
GeneralRe: Sending iterator items to other functions from in a for block.... Pin
Stefan_Lang12-Nov-12 22:38
Stefan_Lang12-Nov-12 22:38 
Questionhelp Pin
thebebo188-Oct-12 11:12
thebebo188-Oct-12 11:12 
JokeRe: help Pin
Peter_in_27808-Oct-12 13:22
professionalPeter_in_27808-Oct-12 13:22 
GeneralRe: help Pin
Sivaraman Dhamodharan8-Oct-12 20:44
Sivaraman Dhamodharan8-Oct-12 20:44 
Questionsetup error Pin
emanalshboul8-Oct-12 9:58
emanalshboul8-Oct-12 9:58 
QuestionRe: setup error Pin
David Crow8-Oct-12 10:32
David Crow8-Oct-12 10:32 
AnswerRe: setup error Pin
Richard MacCutchan8-Oct-12 22:16
mveRichard MacCutchan8-Oct-12 22:16 
QuestionCustomize CFileDialog? Pin
bosfan8-Oct-12 5:05
bosfan8-Oct-12 5:05 
AnswerRe: Customize CFileDialog? Pin
jeron18-Oct-12 5:52
jeron18-Oct-12 5:52 
GeneralRe: Customize CFileDialog? Pin
bosfan8-Oct-12 21:37
bosfan8-Oct-12 21:37 
SuggestionRe: Customize CFileDialog? Pin
David Crow8-Oct-12 6:48
David Crow8-Oct-12 6:48 
GeneralRe: Customize CFileDialog? Pin
bosfan9-Oct-12 3:05
bosfan9-Oct-12 3:05 
AnswerRe: Customize CFileDialog? Pin
Sarath C8-Oct-12 22:35
Sarath C8-Oct-12 22:35 
GeneralRe: Customize CFileDialog? Pin
bosfan9-Oct-12 3:06
bosfan9-Oct-12 3:06 
QuestionHow to associate an index value with the cstring objects in a CStringArray in MFC.? Pin
mbatra318-Oct-12 0:12
mbatra318-Oct-12 0:12 

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.