From: Brian Muth on 30 Apr 2010 18:21 > As I understand it, I'd need a scalar index for a vector. The data I > will be storing in my array doesn't have unique values in either the > "bibNumber" or "source" fields, and my application will be working only > with the "body" values: sorting and searching. Perhaps there's another > way, but the volume here is rather high and seems to call for a binary > search. <sigh...> It sounds like you need something like: struct dbeStruct { int bibNumber; char source; }; std::map<string, dbeStruct> dbeMap; This gives you a mapping between a string (which you can use as a lookup value) and the bibNumber and source character. Now you don't need to bother with binary search algorithm. Mind you, the downside is that you will need to familiarize yourself with STL if this is new to you.
From: Mike Copeland on 30 Apr 2010 18:21 > > Here's a complete program that demonstrates the problem, as well as > > all error diagnostics. TIA > > #include <iostream> > > #include <string> > > using namespace std; > > struct dbeBuild > > { > > int bibNumber; > > char source; > > string body; > > } dbeWork; > > > > dbeBuild *dbeZeroBibs = NULL; > > dbeZeroBibs = new dbeBuild[2505]; // the errors are on this line > > This is outside of any function. The above is a statement that has to be > inside of a function body. > > > // error C2501: 'dbeZeroBibs' : missing storage-class or type specifiers > > // error C2040: 'dbeZeroBibs' : 'int' differs in levels of indirection > > from 'struct dbeBuild *' > [...] Of course! How stupid of me. Sorry for the bother (but thanks!)... However, it _does_ go to prove my point that Microsoft's diagnostics are often incomprehensible. <sigh...> 8<{{
From: Victor Bazarov on 1 May 2010 09:26 Mike Copeland wrote: >>> Here's a complete program that demonstrates the problem, as well as >>> all error diagnostics. TIA >>> #include <iostream> >>> #include <string> >>> using namespace std; >>> struct dbeBuild >>> { >>> int bibNumber; >>> char source; >>> string body; >>> } dbeWork; >>> >>> dbeBuild *dbeZeroBibs = NULL; >>> dbeZeroBibs = new dbeBuild[2505]; // the errors are on this line >> This is outside of any function. The above is a statement that has to be >> inside of a function body. >> >>> // error C2501: 'dbeZeroBibs' : missing storage-class or type specifiers >>> // error C2040: 'dbeZeroBibs' : 'int' differs in levels of indirection >>> from 'struct dbeBuild *' >> [...] > > Of course! How stupid of me. Sorry for the bother (but thanks!)... > However, it _does_ go to prove my point that Microsoft's diagnostics > are often incomprehensible. <sigh...> 8<{{ The diagnostic messages cannot possibly include all education materials for the language you're using. Statements outside of functions are *expected* to be declarations. A declaration without an explicit type is assumed to be of 'int' type (thank C inventors for that and the spirit of "backward compatibility"). Initialization of an 'int' with a pointer produces your "different levels of indirection" message. BTW, VC 2010 gives this diagnostic: test.cpp(12): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int test.cpp(12): error C2040: 'dbeZeroBibs' : 'int' differs in levels of indirection from 'dbeBuild *' test.cpp(12): error C2440: 'initializing' : cannot convert from 'dbeBuild *' to 'int' Of course, it might be more helpful if it immediately flagged the erroneous line as a *redeclaration/redefinition* of the variable, but I guess MSVC developers have better things to do than to look for all possible causes of the compiler's inability to compile a declaration. There is logical explanation for everything, and there are going to be people who aren't satisfied with anything you give them. It's a well known phenomenon that one can't satisfy *everybody*. So, the principle often adhered to is 'sapienti sat'. Get yourself an Express version of Visual Studio 2010, it's *free*. At least you're going to have a modern compiler. And a decent book on C++, while you're at it. Being "quite old" is no excuse for staying behind as far as technology is concerned. And, following a common idiom, you have to realize that you _can't afford *not* to upgrade_ to a new version. As for its being "daunting", I'll give you the very old Russian saying: "Eyes are afraid but hands are doing". Good luck! V -- Please remove capital 'A's when replying by e-mail I do not respond to top-posted replies, please don't ask
From: Thomas J. Gritzan on 1 May 2010 11:53 Am 01.05.2010 15:26, schrieb Victor Bazarov: > Mike Copeland wrote: [statement outside of function] >> Of course! How stupid of me. Sorry for the bother (but >> thanks!)... However, it _does_ go to prove my point that >> Microsoft's diagnostics are often incomprehensible. <sigh...> 8<{{ > > The diagnostic messages cannot possibly include all education materials > for the language you're using. Statements outside of functions are > *expected* to be declarations. A declaration without an explicit type > is assumed to be of 'int' type (thank C inventors for that and the > spirit of "backward compatibility"). Initialization of an 'int' with a > pointer produces your "different levels of indirection" message. > > BTW, VC 2010 gives this diagnostic: > > test.cpp(12): error C4430: missing type specifier - int assumed. Note: > C++ does not support default-int > test.cpp(12): error C2040: 'dbeZeroBibs' : 'int' differs in levels of > indirection from 'dbeBuild *' > test.cpp(12): error C2440: 'initializing' : cannot convert from > 'dbeBuild *' to 'int' > > Of course, it might be more helpful if it immediately flagged the > erroneous line as a *redeclaration/redefinition* of the variable, but I > guess MSVC developers have better things to do than to look for all > possible causes of the compiler's inability to compile a declaration. Using Comeau Online[1], the error messages are much better. It flags the redeclaration and even gives a hint to the cause of the error(s). So the messages MSVC produces can/could be improved: "ComeauTest.c", line 12: error: this declaration has no storage class or type specifier, Wild guess: Should this be in a function block? Wild Guess: You're using export but not using Comeau C++ 4.3.x dbeZeroBibs = new dbeBuild[2505]; ^ "ComeauTest.c", line 12: error: variable "dbeZeroBibs" has already been defined dbeZeroBibs = new dbeBuild[2505]; ^ "ComeauTest.c", line 12: error: a value of type "dbeBuild *" cannot be used to initialize an entity of type "int" dbeZeroBibs = new dbeBuild[2505]; [1] http://www.comeaucomputing.com/tryitout -- Thomas
From: Stephan T. Lavavej [MSFT] on 1 May 2010 23:43 VC10 Intellisense is powered by the EDG compiler front-end, which is the same thing that Comeau is powered by, so hovering over VC10's red squiggles can be especially enlightening. In this case, "dbeZeroBibs" in "dbeZeroBibs = new dbeBuild[2505];" is squiggled, and hovering over it reveals the message: "Error: this declaration has no storage class or type specifier", which says that Intellisense thinks that it's a declaration. "Wild guess: Should this be in a function block?", which is especially helpful, is either Comeau-specific, or not being shown by Intellisense (as a library dev, I don't know the internals here). Also: you should be using std::vector and std::lower_bound(), or std::map, etc. Stephan T. Lavavej Visual C++ Libraries Developer "Thomas J. Gritzan" <phygon_antispam(a)gmx.de> wrote in message news:hrhipn$lda$1(a)newsreader5.netcologne.de... > Am 01.05.2010 15:26, schrieb Victor Bazarov: >> Mike Copeland wrote: > [statement outside of function] >>> Of course! How stupid of me. Sorry for the bother (but >>> thanks!)... However, it _does_ go to prove my point that >>> Microsoft's diagnostics are often incomprehensible. <sigh...> 8<{{ >> >> The diagnostic messages cannot possibly include all education materials >> for the language you're using. Statements outside of functions are >> *expected* to be declarations. A declaration without an explicit type >> is assumed to be of 'int' type (thank C inventors for that and the >> spirit of "backward compatibility"). Initialization of an 'int' with a >> pointer produces your "different levels of indirection" message. >> >> BTW, VC 2010 gives this diagnostic: >> >> test.cpp(12): error C4430: missing type specifier - int assumed. Note: >> C++ does not support default-int >> test.cpp(12): error C2040: 'dbeZeroBibs' : 'int' differs in levels of >> indirection from 'dbeBuild *' >> test.cpp(12): error C2440: 'initializing' : cannot convert from >> 'dbeBuild *' to 'int' >> >> Of course, it might be more helpful if it immediately flagged the >> erroneous line as a *redeclaration/redefinition* of the variable, but I >> guess MSVC developers have better things to do than to look for all >> possible causes of the compiler's inability to compile a declaration. > > Using Comeau Online[1], the error messages are much better. It flags the > redeclaration and even gives a hint to the cause of the error(s). So the > messages MSVC produces can/could be improved: > > "ComeauTest.c", line 12: error: this declaration has no storage class or > type specifier, Wild guess: Should this be in a function block? Wild > Guess: You're using export but not using Comeau C++ 4.3.x > dbeZeroBibs = new dbeBuild[2505]; > ^ > "ComeauTest.c", line 12: error: variable "dbeZeroBibs" has already been > defined > dbeZeroBibs = new dbeBuild[2505]; > ^ > "ComeauTest.c", line 12: error: a value of type "dbeBuild *" cannot be > used to initialize an entity of type "int" > dbeZeroBibs = new dbeBuild[2505]; > > [1] http://www.comeaucomputing.com/tryitout > > -- > Thomas
First
|
Prev
|
Pages: 1 2 Prev: initialize the pointer structure Next: Reversing 2nd order deep std::vector |