(C++) Expression must have a constant value [duplicate]












-1















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
enter image description here



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.










share|improve this question















marked as duplicate by juanchopanza, Neil Butterworth, Mike Kinghan, πάντα ῥεῖ c++
Users with the  c++ badge can single-handedly close c++ questions as duplicates and reopen them as needed.

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, where count 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 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


















-1















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
enter image description here



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.










share|improve this question















marked as duplicate by juanchopanza, Neil Butterworth, Mike Kinghan, πάντα ῥεῖ c++
Users with the  c++ badge can single-handedly close c++ questions as duplicates and reopen them as needed.

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, where count 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 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
















-1












-1








-1








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
enter image description here



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.










share|improve this question
















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
enter image description here



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++






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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, πάντα ῥεῖ c++
Users with the  c++ badge can single-handedly close c++ questions as duplicates and reopen them as needed.

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, πάντα ῥεῖ c++
Users with the  c++ badge can single-handedly close c++ questions as duplicates and reopen them as needed.

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, where count 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 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
















  • 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






  • 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 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










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














1 Answer
1






active

oldest

votes


















1














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);





share|improve this answer




























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    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);





    share|improve this answer


























      1














      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);





      share|improve this answer
























        1












        1








        1






        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);





        share|improve this answer












        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);






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 18 '18 at 19:53









        ΦXocę 웃 Пepeúpa ツΦXocę 웃 Пepeúpa ツ

        32.9k113860




        32.9k113860















            Popular posts from this blog

            How to change which sound is reproduced for terminal bell?

            Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

            Can I use Tabulator js library in my java Spring + Thymeleaf project?