0

This is probably a very easy question, but for some reason I don'd understand what I'm doing wrong here.

Anyways, I got a function that takes in function(size_type m, size_type n) and I have to build an array which is pointed to by a private variable in the class called int *value. I am trying to create an integer array of mxn size but I am having difficulty changing the type of m and n.

I tried:

*value = int[(int)m*(int)n];

as well as using (unsigned int) can someone please help.

EDIT: size_type isn't declared as any type in the specs

1
  • 2
    provide more source code....tsss...what is size_type??????? Commented Aug 26, 2011 at 11:29

2 Answers 2

6

You may consider:

value = new int[m*n];

because you need to create a dynamic array. You will need to remember to delete [] this at the correct times.

You will probably find it easier to work with a std::vector, because the memory management is handled for you.

Sign up to request clarification or add additional context in comments.

Comments

0

How about this?

typedef int size_type; //could also be this or that other type...

void myFunction(size_type m, size_type n)
{
   int array[(int) m * (int) n ];
   int *value = array;
};

int main()
{
   myFunction(2, 2);
   return 0;
}

Or do you need value outside of the function? Do you want the function to return the value?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.