| | |
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 |
Tag cloud for C++
api application array arrays assignment beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete developer display dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator getline givemetehcodez graph iamthwee ifstream image input int java lib list loop looping loops map math matrix memory multidimensional multiple newbie news node number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






