1
int place = determinePlace(input);

const int arraySize = (place + 1);
int decimal[arraySize] = {};

Hi!

I tried to use a const int variable to define the array size of decimal[]. However, error C2057 and error C2466 keeps on coming up.

Are there any suggestions?

2
  • 2
    For the future, it would be nice if you could include the actual error messages rather than just the error numbers. Those error numbers are compiler specific, and i don't think anyone has them memorized. Commented Jun 27, 2015 at 16:00
  • Maybe use a constexpr (but that probably won't work here, unless determinePlace is a constexpr function, and input is a constexpr also; which is very unlikely) Commented Jun 27, 2015 at 16:18

3 Answers 3

2

Even if you declare arraySize as const, it's still not a compile-time constant since it have to be calculated run-time.

Use std::vector instead:

std::vector<int> decimal(arraySize);
Sign up to request clarification or add additional context in comments.

Comments

1

array size should be int , unsigned, unsigned int or size_t not a decimal type double

use std::vector

to use

#include <vector> // include the header 

to define a vector

std::vector<int> vec = {1, 2, 3, 4, 5};

this defines vector int with a values of 1, 2, 3, 4, 5

to add some values

vec.push_back(12);

adds 12 to vec vector

Comments

0

Joachim is right, you are trying to set:

const int arraySize = (determinePlace(input) + 1);

this doesn't work, because you are trying to get a user input or something similar which will be only accessible when you run the program not when you compile it.

I would try something like this:

#include <vector>

using std::vector;

vector<int> decimal;
decimal.resize(determinePlace(input) +1);
decimal = {};

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.