(C++) Expression must have a constant value [duplicate]
This question already has an answer here:
Using const int as array size
5 answers
Visual Studio is for some weird reason showing me this error and keep saying that count is not const int while trying to initialised array. Check image.
Error: expression must have a constant value
This is function call at main:
std::string fileName("shows.tv");
const int COUNT = 10;
Episode** episodes = loadEpisodesFromFile(fileName, COUNT);
and this is function declaration at header file:
Episode** loadEpisodesFromFile(std::string, const int);
I don't get it. Variable count is already declared as const int but it's not working.
c++
marked as duplicate by juanchopanza, Neil Butterworth, Mike Kinghan, πάντα ῥεῖ
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 18 '18 at 19:53
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
|
show 4 more comments
This question already has an answer here:
Using const int as array size
5 answers
Visual Studio is for some weird reason showing me this error and keep saying that count is not const int while trying to initialised array. Check image.
Error: expression must have a constant value
This is function call at main:
std::string fileName("shows.tv");
const int COUNT = 10;
Episode** episodes = loadEpisodesFromFile(fileName, COUNT);
and this is function declaration at header file:
Episode** loadEpisodesFromFile(std::string, const int);
I don't get it. Variable count is already declared as const int but it's not working.
c++
marked as duplicate by juanchopanza, Neil Butterworth, Mike Kinghan, πάντα ῥεῖ
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 18 '18 at 19:53
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
1
Episode* episodes[count];
this is the actual error line, wherecount
is a function parameter, this is what you should highlight in the question
– Piotr Skotnicki
Nov 18 '18 at 19:46
1
Can you provide a Minimal, Complete, and Verifiable example reproducing that problem as required here please!
– πάντα ῥεῖ
Nov 18 '18 at 19:46
Not totally sure on this, but do you maybe have another variable defined as "count" as a global that this might be getting confused with?
– tomh1012
Nov 18 '18 at 19:47
The error sayingconstant value
doesn't refer to the same thing as aconst
variable. It needs to be known at compile time. Use astd::vector
to allocate dynamic arrays.
– super
Nov 18 '18 at 19:48
I don't have any global variables. It's school task we are not allowed to usestd::vector
– E. Đordan
Nov 18 '18 at 19:49
|
show 4 more comments
This question already has an answer here:
Using const int as array size
5 answers
Visual Studio is for some weird reason showing me this error and keep saying that count is not const int while trying to initialised array. Check image.
Error: expression must have a constant value
This is function call at main:
std::string fileName("shows.tv");
const int COUNT = 10;
Episode** episodes = loadEpisodesFromFile(fileName, COUNT);
and this is function declaration at header file:
Episode** loadEpisodesFromFile(std::string, const int);
I don't get it. Variable count is already declared as const int but it's not working.
c++
This question already has an answer here:
Using const int as array size
5 answers
Visual Studio is for some weird reason showing me this error and keep saying that count is not const int while trying to initialised array. Check image.
Error: expression must have a constant value
This is function call at main:
std::string fileName("shows.tv");
const int COUNT = 10;
Episode** episodes = loadEpisodesFromFile(fileName, COUNT);
and this is function declaration at header file:
Episode** loadEpisodesFromFile(std::string, const int);
I don't get it. Variable count is already declared as const int but it's not working.
This question already has an answer here:
Using const int as array size
5 answers
c++
c++
edited Nov 18 '18 at 19:49
ΦXocę 웃 Пepeúpa ツ
32.9k113860
32.9k113860
asked Nov 18 '18 at 19:43
E. ĐordanE. Đordan
62
62
marked as duplicate by juanchopanza, Neil Butterworth, Mike Kinghan, πάντα ῥεῖ
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 18 '18 at 19:53
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by juanchopanza, Neil Butterworth, Mike Kinghan, πάντα ῥεῖ
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 18 '18 at 19:53
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
1
Episode* episodes[count];
this is the actual error line, wherecount
is a function parameter, this is what you should highlight in the question
– Piotr Skotnicki
Nov 18 '18 at 19:46
1
Can you provide a Minimal, Complete, and Verifiable example reproducing that problem as required here please!
– πάντα ῥεῖ
Nov 18 '18 at 19:46
Not totally sure on this, but do you maybe have another variable defined as "count" as a global that this might be getting confused with?
– tomh1012
Nov 18 '18 at 19:47
The error sayingconstant value
doesn't refer to the same thing as aconst
variable. It needs to be known at compile time. Use astd::vector
to allocate dynamic arrays.
– super
Nov 18 '18 at 19:48
I don't have any global variables. It's school task we are not allowed to usestd::vector
– E. Đordan
Nov 18 '18 at 19:49
|
show 4 more comments
1
Episode* episodes[count];
this is the actual error line, wherecount
is a function parameter, this is what you should highlight in the question
– Piotr Skotnicki
Nov 18 '18 at 19:46
1
Can you provide a Minimal, Complete, and Verifiable example reproducing that problem as required here please!
– πάντα ῥεῖ
Nov 18 '18 at 19:46
Not totally sure on this, but do you maybe have another variable defined as "count" as a global that this might be getting confused with?
– tomh1012
Nov 18 '18 at 19:47
The error sayingconstant value
doesn't refer to the same thing as aconst
variable. It needs to be known at compile time. Use astd::vector
to allocate dynamic arrays.
– super
Nov 18 '18 at 19:48
I don't have any global variables. It's school task we are not allowed to usestd::vector
– E. Đordan
Nov 18 '18 at 19:49
1
1
Episode* episodes[count];
this is the actual error line, where count
is a function parameter, this is what you should highlight in the question– Piotr Skotnicki
Nov 18 '18 at 19:46
Episode* episodes[count];
this is the actual error line, where count
is a function parameter, this is what you should highlight in the question– Piotr Skotnicki
Nov 18 '18 at 19:46
1
1
Can you provide a Minimal, Complete, and Verifiable example reproducing that problem as required here please!
– πάντα ῥεῖ
Nov 18 '18 at 19:46
Can you provide a Minimal, Complete, and Verifiable example reproducing that problem as required here please!
– πάντα ῥεῖ
Nov 18 '18 at 19:46
Not totally sure on this, but do you maybe have another variable defined as "count" as a global that this might be getting confused with?
– tomh1012
Nov 18 '18 at 19:47
Not totally sure on this, but do you maybe have another variable defined as "count" as a global that this might be getting confused with?
– tomh1012
Nov 18 '18 at 19:47
The error saying
constant value
doesn't refer to the same thing as a const
variable. It needs to be known at compile time. Use a std::vector
to allocate dynamic arrays.– super
Nov 18 '18 at 19:48
The error saying
constant value
doesn't refer to the same thing as a const
variable. It needs to be known at compile time. Use a std::vector
to allocate dynamic arrays.– super
Nov 18 '18 at 19:48
I don't have any global variables. It's school task we are not allowed to use
std::vector
– E. Đordan
Nov 18 '18 at 19:49
I don't have any global variables. It's school task we are not allowed to use
std::vector
– E. Đordan
Nov 18 '18 at 19:49
|
show 4 more comments
1 Answer
1
active
oldest
votes
Episode* episodes[count]
is not valid because count is a parameter from the function
loadEpisodesFromFile which is unknown at compiling time...
you need to use an std::vector instead
std::vector<Episode*> episodes(count);
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Episode* episodes[count]
is not valid because count is a parameter from the function
loadEpisodesFromFile which is unknown at compiling time...
you need to use an std::vector instead
std::vector<Episode*> episodes(count);
add a comment |
Episode* episodes[count]
is not valid because count is a parameter from the function
loadEpisodesFromFile which is unknown at compiling time...
you need to use an std::vector instead
std::vector<Episode*> episodes(count);
add a comment |
Episode* episodes[count]
is not valid because count is a parameter from the function
loadEpisodesFromFile which is unknown at compiling time...
you need to use an std::vector instead
std::vector<Episode*> episodes(count);
Episode* episodes[count]
is not valid because count is a parameter from the function
loadEpisodesFromFile which is unknown at compiling time...
you need to use an std::vector instead
std::vector<Episode*> episodes(count);
answered Nov 18 '18 at 19:53
ΦXocę 웃 Пepeúpa ツΦXocę 웃 Пepeúpa ツ
32.9k113860
32.9k113860
add a comment |
add a comment |
1
Episode* episodes[count];
this is the actual error line, wherecount
is a function parameter, this is what you should highlight in the question– Piotr Skotnicki
Nov 18 '18 at 19:46
1
Can you provide a Minimal, Complete, and Verifiable example reproducing that problem as required here please!
– πάντα ῥεῖ
Nov 18 '18 at 19:46
Not totally sure on this, but do you maybe have another variable defined as "count" as a global that this might be getting confused with?
– tomh1012
Nov 18 '18 at 19:47
The error saying
constant value
doesn't refer to the same thing as aconst
variable. It needs to be known at compile time. Use astd::vector
to allocate dynamic arrays.– super
Nov 18 '18 at 19:48
I don't have any global variables. It's school task we are not allowed to use
std::vector
– E. Đordan
Nov 18 '18 at 19:49