Advertisement

Help with arrays...

Started by January 18, 2003 01:25 PM
4 comments, last by Sky 22 years, 1 month ago
Here''s what i''m trying to do... float array[3]; and then later in the program just define all the variables in the array at once... array[] = {1,2,3}; What is the proper syntax for this? Or is it even possible? i know you can define them all when you initialize the array, But I can''t find any information about how to/if you can do it later in the program...
The syntax you are trying to use is only valid during the initial definition of the array. Once the array has been defined, you can only assign individual elements.


[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Advertisement
grr.. thats a pain. It seems like you should be able too ::grumble::
Here''s some homework for you : try to either find a technical reason why you cannot do it or how you could modify a compiler to let you do it while keeping your arrays binary-compatible with C.

It''s very instructive.


[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
I don''t see any reason why the compiler wouldn''t be able to do it. I mean I could easily make a function to do the exact same thing... (except for the fact that I don''t know how to pass array''s through functions and I don''t know nearly enough to make it so that just doing like array[whatever] = {33,43,3,1,2} would work. (though if I new more commands I think I would be able too...))
This is a crappy solution to your problem, but you could just do the initial definition of your array after you have the values you want to insert. You don''t have declare your array at the start of a function it''s just good coding practice.
"If all else fails, lower your standards."

This topic is closed to new replies.

Advertisement