Passing by reference using pointers

I am trying to load in an array of values into a memory location. I am new to C++ and currently have this code in the main:

main file
int program = {1007, 1008, 2007, 3008, 2109, 1109, 4300};
int memory[100];

class.h file
void loadProgramIntoMemory(int *program);

class.cpp
void loadProgramIntoMemory(int *program);
{

{

Couldn't work out what I needed to put into the .cpp file for it to successfully work.
Last edited on
First off, the following line needs to be an array:
 
  int program = {1007, 1008, 2007, 3008, 2109, 1109, 4300};

You can't load 7 values into a single int.

If you want to load the values from program into memory, you're going to need to pass both arrays to your function, along with the number of values to move.

In your class.cpp file, the following line shot NOT have a ;
 
void loadProgramIntoMemory(int *program);  // <- Remove the ; 


Your function prototype should probably look more like this:
 
void loadProgramIntoMemory (const int *program, int * memory, int size);


PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
Last edited on
Hi, thanks for that those errors were mostly from me adjusting and deleting code to try and get some functionality. I have made those adjustments now and I was wondering how you would go about passing the arrays into the function?
Do you know how to call a function?
http://www.cplusplus.com/doc/tutorial/functions/

 
  loadProgramIntoMemory (program, memory, 7);

Topic archived. No new replies allowed.