Grabbing a reference to or pointer to...

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2009
Posts: 22
Reputation: pac-man is an unknown quantity at this point 
Solved Threads: 0
pac-man pac-man is offline Offline
Newbie Poster

Grabbing a reference to or pointer to...

 
0
  #1
21 Days Ago
Hi guys,

I was hoping someone could explain to me how I would go about grabbing a pointer/reference to my variable 'textName' contained within the Reports class, (some code omitted to try to simplify the scenario)

  1. //Reports.h
  2. class Reports : public wxPanel
  3. {
  4. public:
  5. void AddStudent(wxCommandEvent & event);
  6. wxTextCtrl *textName; // declare variable
  7. };
  1. //Reports.cpp
  2. Reports::Reports(wxPanel * parent)
  3. : wxPanel(parent, wxID_ANY, wxPoint(-1, -1), wxSize(500, 500))
  4. {
  5.  
  6. wxTextCtrl *textName = new wxTextCtrl(this, wxID_AddStudent, wxT(""), wxPoint(65, 65));
  7.  
  8. }
  9.  
  10. void Reports::AddStudent(wxCommandEvent & WXUNUSED(event))
  11. {
  12. // The following breaks the code, I want to grab textName
  13. textName.SetValue("Test");
  14. textName.SetFocus();
  15.  
  16. /* *************************
  17. If I re-create textName then access (as shown in the following
  18.   commented code) then it works fine but I can't
  19.   work out how to create a pointer/reference to the
  20.   previous textName rather than having to re-create one!
  21.  
  22. wxTextCtrl *textName = new wxTextCtrl(this,wxID_AddStudent, wxT("Another button..."), wxPoint(65, 95));
  23.  
  24. textName->SetValue("Testing");
  25. textName->SetFocus();
  26. *******************************/
  27.  
  28. }
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 22
Reputation: pac-man is an unknown quantity at this point 
Solved Threads: 0
pac-man pac-man is offline Offline
Newbie Poster
 
0
  #2
21 Days Ago
I worked it out.

Thanks
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC