| | |
acessing a vector outside its class
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Feb 2008
Posts: 25
Reputation:
Solved Threads: 0
Hi,
I'm doing a program that has a class called Liga. That class has a vector with 'Equipa's.
Liga has a vector called 'pessoas' which I want to access inside a function in each Equipa, is this possible?
for example:
Liga.h
Equipa.cpp
thanks in advance!
I'm doing a program that has a class called Liga. That class has a vector with 'Equipa's.
Liga has a vector called 'pessoas' which I want to access inside a function in each Equipa, is this possible?
for example:
Liga.h
C++ Syntax (Toggle Plain Text)
... vector<Pessoa*> pessoas; ...
Equipa.cpp
C++ Syntax (Toggle Plain Text)
... void Equipa::mostraStaff() {<blockquote>for(unsigned int i=0;i!=pessoas.size();i++)<blockquote>pessoas[i].mostra();</blockquote></blockquote>} ...
thanks in advance!
Last edited by onemanclapping; Oct 7th, 2008 at 10:06 pm.
•
•
Join Date: Oct 2007
Posts: 305
Reputation:
Solved Threads: 43
Yes you can make it public and add the header to Equipa. If you want only Equipa to access the data members of Liga, and not any other class, then you can declare it as a friend:
class Liga {
friend class Equipa;
....
};•
•
Join Date: Feb 2008
Posts: 25
Reputation:
Solved Threads: 0
•
•
•
•
>that's good! I just need to declare it as public
It's rather depressing how you latched on to the worst possible option that stilllearning suggested.

I modified my primary algorithm and now I don't need to do that anymore

thanks for all your help, though!
![]() |
Other Threads in the C++ Forum
- Previous Thread: two webcams with OpenCV
- Next Thread: Hello. Need help with a class problem
| Thread Tools | Search this Thread |
api application array arrays based beginner binary c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg simple sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






