Menu

Expected Identifier before string const

2017-10-20
2017-10-23
  • Somasekara Rao Manda

    Hi all,

    I am simply calling initializing CWorkbook as follows. error while compling.

    CWorkbook book( _T("Incognito") );
    error: expected identifier before string constant
    CWorkbook book( _T("Incognito") );
    ^
    /Xlsx/../tchar.h:177:16: note: in definition of macro '_T'
    #define _T(x) x
    ^
    error: expected ',' or '...' before string constant
    CWorkbook book( _T("Incognito") );
    ^
    please letme know why can't I initialize;

     
  • Somasekara Rao Manda

    I am initializing
    CWorkbook book( _T("Incognito") ); as an attribute of a class name TracingResultExporter; The above compilation error comes.

    please suggest me. where I am doing mistake.

     
  • Alexandr Belyak

    Alexandr Belyak - 2017-10-20

    Hi,
    If I understand you correctly, than the compiler has counted your class variable as a class function.
    This is an invalid declaration of a class variable. Your code should be something like this:
    Header file:

    class TracingResultExporter
    {
        public:
            TracingResultExporter();
        private:
            CWorkbook book;
    };
    

    Cpp file:

    TracingResultExporter::TracingResultExporter() : book( _T( "Incognito" ) )
    {
    
    }
    

    If this does not work, show your minimum non-working code and write the name of your IDE.

     
  • Somasekara Rao Manda

    Hi Alexandr, thank you so much. Done its working.

     
  • Alexandr Belyak

    Alexandr Belyak - 2017-10-23

    You're welcome :-)

     

Log in to post a comment.