How to pass a pointer to a class variable to a function

I am new to C++ and am taking a class for it, but we are not covering many things. One of the things we will not cover is dynamic memory allocation.

I have a home project, not homework, I am trying to finish, but can't seem to work with dma and functions well.

In my mian() function I have this bit of code to allocate some space for some class variables:

1
2
Book * biblio;
      biblio = new Book [menStruct.menuCounter];


Later I have a function that will be displaying the elements of these class variables to the screen. Here is the snippet for that code:

1
2
3
4
5
6
printf("%u%s", lineCounter, ".  ");
      cout << biblio[lineCounter - 1].getTitle();
      printf("%*s", (tmpL - selection.length()) + 1, " ");
      cout << "   "
	   << newAuthor
           << '\n';


Now this setup works just fine as long as it remains in the main() function, but when I try to place it in a function, I get errors about undeclared variables and unexpected types.

Here is a generalization of the code I am trying to make a function:

This is the prototype so far, I need to figure out how to deal with the arguments.

residualMenuData mainScreen(unsigned int tmpL, unsigned int tmpLii);

This is the definition of the function:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
residualMenuData mainScreen(unsigned int tmpL, unsigned int tmpLii)
      {
          unsigned int lineCounter = 0;

	  menStruct.menuCounter = 0;

	  ifstream input("input.txt", ios::in | ios::binary);
		
	  while(getline(input, string()))
	  {
	      menStruct.menuCounter++;
	  }

	  input.clear();
	  input.seekg(0, ios::beg);

	  menuHoofer(tmpL, tmpLii);

	  cout << "Books Currently Available"
	       << "\n\n";

	  printf("%s%*s%s\n", "    TITLE", (tmpL - 30), " ", "AUTHOR");
	  printf("%s%*s%s\n", "    -----", (tmpL - 30), " ", "------");

	  printf("%u%s", lineCounter, ".  ");
	  cout << biblio[lineCounter - 1].getTitle();
	  printf("%*s", (tmpL - selection.length()) + 1, " ");
	  cout << "   "
	       << newAuthor
	       << '\n';

	  menuHoofer(tmpL, tmpLii);

	  return menStruct;
	  }


My main question is how do I pass my class variables to the function?

I have tried juggling my arguments around and using every mention of Book, class, biblio, and * that I can think of and notta. Any help would be greatly appreciated.
Topic archived. No new replies allowed.