now in another class I pass the vectors of node and elements objects by reference into constructor and I need to use the constructor and methods of Node and Element class inside the third one. I made the third class as children of these two classes but still I am not able to do that. any help would be appreciated.
Assembler::Assembler(VecNode_t &Nodes, VecElm_t &Elements){
for (int i = 0; i < Elements.size(); i++)
{
Elements[i]./*after this dot I need to see the memebr function of other class but nothing*/
}
}
I can't access to the Node0,Node1,Node2 or size of element. it prints me nothing. how I can have a loop over the number of elements, get the Node0,Node1,Node2 and Elmsize?
class Elements {
// some private members
public:
Element( VecIdx_t* , VecNode_t& );
void set_vertices( VecIdx_t* );
};
// and
std::vector<Element> Elements;
Assembler is another class for assembling the global stiffness matrix in finite element method. I haven't finished writing of that class yet because I had some problem accessing data(class variable).It requires local stifness matrix and the local stifness matrix take the variable of class node and element.
Node0,Node1 and Node2 are class variables and elm is an object of class, why I can't access to the data in the way I showed?
I tried your way and still it's not printing anything.
and here is class Element,not Elements. Elements is the vector of Element objects.
1 2 3 4 5 6
class Element {
// some private members
public:
Element( VecIdx_t* , VecNode_t& );
void set_vertices( VecIdx_t* );
};
Why nothing is happening here Elements[i_elm].Node0;
What do you expect that to do?
Lets take similar case:
1 2
int x = 42;
x; // What does this statement do?
I tried your way and still it's not printing anything.
Of course it does not print, because I did not nor could not do anything about that problem.
when here I can do the same ... std::cout << Nodes[i_node].get_x();
That calls member function get_x() of a Node object.
Node0,Node1 and Node2 are class variables ...
1 2 3 4 5 6
class Element {
// some private members
public:
Element( VecIdx_t* , VecNode_t& );
void set_vertices( VecIdx_t* );
};
If they are members of the Element, why didn't you show their declarations within the definition of Element?
That seems to be elemental for solving your issue.
my bad, this thread doesn't have that. I am just confused with something. Imagine in a class we defined some variables. Then we have different member functions. These member functions are not single task, they do different things inside but in the middle they calculate some of those class variables.
For example N0,N1 and N2 are class variable and we have a member function
void dosomething(some arguments) and inside "dosomething" one of the outputs will be the N0. Now in order to get N0 should I first make an object of class, then call this member function like below?
Class object;
object.dosomething(some arguments);
object.N0;
is that the way to access member variable?
What you wrote is valid syntax. dosomething is a member function of the object of type 'Class', and N0 is a member variable of the object. You don't do anything with N0, however. I'm not sure if this answers your question. Perhaps reword it.
class N {
// ???
};
class Class {
public:
void dosomething(int foo, int bar, int baz)
{
}
N N0;
};
int main()
{
Class object;
object.dosomething(1, 2, 3);
object.N0; // warning: statement has no effect [-Wunused-value]
}
object.N0; // warning: statement has no effect [-Wunused-value]
foo = object.N0; // ok, read value of member and store it in 'foo'
object.N0 = bar; // ok, modify value of member
Outsiders might not access any member variable directly, just call member functions:
class Class {
private:
N N0;
public:
void dosomething(int foo, int bar, int baz)
{
// modify N0
}
double getresult()
{
// return something from N0
}
};
int main()
{
Class object;
object.dosomething(1, 2, 3);
double result = object.getresult();
}