A member function is not going to be able to access variables from the main function, only from the class itself. Now if item item1; were declared in person (so that every person had an item "inside" him), then it would work.