do i use extern if i need to access my local db in another cpp file?
hi. i have basic question. please see below where i put the !!!!!
//myObj.hpp
class myObj
{
data
functions etc...
}
//myObj.cpp
myObj::etc...
//myMain.cpp
main
{
map<int, myObj> myLocalData;
}
//somethingElse.hpp
class somethingElse
{
data...
memberfunctions...
}
//somethingElse.cpp
somethingElse::somefuntion
{
access whats in my myLocalData Map; !!!!!!!!!!!!!!!!!!!!!!
}
now how can i accesss myLocalData in another .cpp file? Do i use
"extern map<int, myObj> myLocalData" in the somethingElse.cpp?
Thanks
If you want to access a local variable in another function you'll need to pass a pointer or reference to the variable as an argument to the function. You can also make the variable a global variable by removing it from the function definition and externing it in a header as normal for global variables.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement