template parameter!

closed account (28poGNh0)
using namespace std;

# include <vector>
using std::vector;

class myClass
{
public :
myClass(void);
public :
vector<string>VS;
};

myClass::myClass(void)
{
string str1 = "First string";
string str2 = "Second string";

VS.push_back(str1);
VS.push_back(str2);
}

class mainClass
{
public :
mainClass(void);
~mainClass();

void function(void);

myClass *names;
};

mainClass::mainClass(void)
{
names = new myClass();

function();
}

mainClass::~mainClass()
{
delete names;
}

void mainClass::function(void)
{
// How to get VS'whole's package in here
}

int main()
{
myClass someName;
}
/*
Hey everyone this code is bit long and I apologize for that,hope you help on this one It given me so
much pain,I cant sleep ,I cant eat ,I can't find any book talking about It :)
what I am trying to do is to get elements of the vector VS into mainClass as parameter and I dont
know how to do It ,so can you help me
thanks a lot
*/
VS is a public member of myClass.

You have *names which points to a myClass and contains a VS.

Therefore to access VS from a function in mainClass you can do this:
1
2
3
4
void mainClass::function(void)
{
    names->VS.push_back("Hello");
}


Now go eat something.
closed account (28poGNh0)
Thanks a lot @Stewbond
Topic archived. No new replies allowed.