"Array bounds not an interger constant" except it is.

This is a discussion on "Array bounds not an interger constant" except it is. within the C++ Programming forums, part of the General Programming Boards category; I'm getting this error, which doesn't make any sense to me because the array bounds is an integer constant. Any ...

  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    119

    "Array bounds not an interger constant" except it is.

    I'm getting this error, which doesn't make any sense to me because the array bounds is an integer constant. Any idea why the compiler thinks it's not an integer constant?

    The following code gives me the error

    bar.hxx
    Code:
    #ifndef _BAR_H
    #define _BAR_H
    #include "foo.hxx"
    
    class Bar
    {
    public:
    	Bar();
    	
    private:
    	int test[foo_types::MY_CONST];
    };
    #endif
    bar.cxx
    Code:
    #include "bar.hxx"
    
    int main(void)
    {
    	Bar b;
    	
    }
    foo.hxx
    Code:
    #ifndef _FOO_H_
    #define _FOO_H_
    struct foo_types
    {
    	static const int MY_CONST;
    };
    #endif
    foo.cxx
    Code:
    #include "foo.hxx"
    
    const int foo_types::MY_CONST = 5;

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,556
    Well the = 5 part is in a source file, which is inaccessible to the module you're trying to use it in.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Nov 2008
    Posts
    119
    Ugh, I was afraid that might be the case. I did try initializing the const in the header and that worked fine. I thought the other header was have access to the const value since adding
    Code:
    	inline int asdf(void)
    	{
    		int x = foo_types::MY_CONST;
    		return x;
    	}
    to the Bar class works fine.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. "warning: multi-line character constant"
    By Benzakhar in forum C++ Programming
    Replies: 7
    Last Post: 08-24-2008, 03:29 PM
  2. Checking for "out of bounds" address?
    By cpjust in forum C Programming
    Replies: 11
    Last Post: 10-31-2007, 11:10 AM
  3. Replies: 2
    Last Post: 09-12-2006, 04:50 AM
  4. "itoa"-"_itoa" , "inp"-"_inp", Why some functions have "
    By L.O.K. in forum Windows Programming
    Replies: 5
    Last Post: 12-08-2002, 07:25 AM
  5. "CWnd"-"HWnd","CBitmap"-"HBitmap"...., What is mean by "
    By L.O.K. in forum Windows Programming
    Replies: 2
    Last Post: 12-04-2002, 06:59 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21