Hi,
This is prity basic question but I am a little stuck with it. I have a class with a member variable in it. There are three files, say a, b and c.
in file b.cpp -

class b
{
public:
   -----
   -----
   int i;
}

in file c.cpp -

int callbvariable()
{
   int w;
   i = w // here I have to call the b member variable
}

// some other class
-----

Both file are than included in the a.cpp file and class b is initialized. Now I don't understand how do I get the pointer of the class b in the function callbvariable()?

Thanks in advance,
Regards.

I generally prefer giving personalized answers, but your question indicates serious misunderstanding of basic concepts of class / object / variables / member / ... I think it would be better if you read this tutorial on classes, which certainly answers your question better than I could.

Member Avatar for Astreios

You could have the callbvariable function take an object of class b as a parameter, and then pass the object you initialized in a.cpp into it.

int callbvariable( B* obj ) {
    int w;
    obj->i = w; // Assuming you wanted to set i equal to w.
}

Edit: I'm sorry, I didn't see mike's reply.

sorry, that is what I wanted to edit but I could not edit it because somehow the edit button got invisible. That function should be -

int callbvariable(lua_State* L)
{
   int w;
   pointer.i = w;
   //other stuff
   return 2;
}

Than it is registered. Lua is working fine.

Thanks for the reply,
Regards.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.