CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2005
    Location
    Detroit MI
    Posts
    80

    What's wrong with this 'const' array decleration?

    Code:
    static const string Alphabet[] = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", x", "y", "z" };
    I keep getting the following compilation errors :

    d:\projects\handlib\handlib\handlib.h(92) : error C2059: syntax error : '{'
    d:\projects\handlib\handlib\handlib.h(92) : error C2334: unexpected token(s) preceding '{'; skipping apparent function body

    Thanks

    BW!
    Regards,

    Big Winston

  2. #2
    Join Date
    Feb 2006
    Location
    London
    Posts
    238

    Re: What's wrong with this 'const' array decleration?

    .h file:
    Code:
     
    #pragmaonce
    
    #include <string>
    
    class A
    
    {
    
    public:
    
    A(void);
    
    ~A(void);
    
    staticconst std::string array[];
    
    };
    
    
    .cpp
    Code:
     
    #include ".\a.h"
    
    const std::string A::array[] = {"a", "b"};
    
    A::A(void)
    
    {
    
    }
    
    A::~A(void)
    
    {
    
    }
    
    

  3. #3
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: What's wrong with this 'const' array decleration?

    Well, it's ok, but you missed a double quote here:
    Code:
    "w", x", "y", "z" };
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured