From: Mike Copeland on 30 Apr 2010 13:56 I'm trying to declare and define a variable array - one which I intend to populate, sort and access via a binary search. My problem is that I cannot seem to convert scalar type dynamic allocation to that of a structure I've created. Here's my structure: struct dbeStruct { int bibNumber; char source; string body; } dbeWork; Here's my code attempt to define a dynamic array of this data: dbeStruct *dbeZeroBibs = NULL; dbeZeroBibs = new dbeStruct[2505]; I don't know what I've done wrong, and I don't understand the error diagnostic (C2501) I'm getting from the (VS6.0) compiler. Please advise. TIA
From: Victor Bazarov on 30 Apr 2010 14:46 On 4/30/2010 1:56 PM, Mike Copeland wrote: > I'm trying to declare and define a variable array - one which I > intend to populate, sort and access via a binary search. My problem is > that I cannot seem to convert scalar type dynamic allocation to that of > a structure I've created. Here's my structure: > > struct dbeStruct > { > int bibNumber; > char source; > string body; > } dbeWork; What's 'dbeWork'? You're defining an object here where you define the struct? > > Here's my code attempt to define a dynamic array of this data: > > dbeStruct *dbeZeroBibs = NULL; > dbeZeroBibs = new dbeStruct[2505]; > > I don't know what I've done wrong, and I don't understand the error > diagnostic (C2501) I'm getting from the (VS6.0) compiler. Please > advise. TIA Post the shortest example that gives you that error, then post the *exact* compiler diagnostic. Consider that while some of us may still have VC6 lying around, it's likely that we don't have the ability to use *that* old of a compiler to try your code. BTW, why don't you upgrade? Also, why don't you use 'std::vector<dbeStruct>' instead of the dynamic array? It's so much easier to let the Standard Library functionality handle dynamic memory allocation... V -- I do not respond to top-posted replies, please don't ask
From: Mike Copeland on 30 Apr 2010 17:31 > > I'm trying to declare and define a variable array - one which I > > intend to populate, sort and access via a binary search. My problem is > > that I cannot seem to convert scalar type dynamic allocation to that of > > a structure I've created. Here's my structure: > > > > struct dbeStruct > > { > > int bibNumber; > > char source; > > string body; > > } dbeWork; > > What's 'dbeWork'? You're defining an object here where you define the > struct? Yes, I'm defining an object variable of the struct type. Is there something wrong with that? > > > > Here's my code attempt to define a dynamic array of this data: > > > > dbeStruct *dbeZeroBibs = NULL; > > dbeZeroBibs = new dbeStruct[2505]; > > > > I don't know what I've done wrong, and I don't understand the error > > diagnostic (C2501) I'm getting from the (VS6.0) compiler. Please > > advise. TIA > > Post the shortest example that gives you that error, then post the > *exact* compiler diagnostic. I will do that, in a followup post. > Consider that while some of us may still > have VC6 lying around, it's likely that we don't have the ability to use > *that* old of a compiler to try your code. BTW, why don't you upgrade? Because I can't afford to purchase a new version...and 6.0 is all I have. Also, I'm quite old and I tend to be leary of the effort to upgrade to something (conversions, porting of existing code/applications) that is unknown. Yes, that's not a good argument, but I have ~1,000,000 lines of code and upgrading to (what?) is very daunting. > Also, why don't you use 'std::vector<dbeStruct>' instead of the dynamic > array? It's so much easier to let the Standard Library functionality > handle dynamic memory allocation... 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...>
From: Mike Copeland on 30 Apr 2010 17:48 > > struct dbeStruct > > { > > int bibNumber; > > char source; > > string body; > > } dbeWork; > > What's 'dbeWork'? You're defining an object here where you define the > struct? > > > > > Here's my code attempt to define a dynamic array of this data: > > > > dbeStruct *dbeZeroBibs = NULL; > > dbeZeroBibs = new dbeStruct[2505]; > > > > I don't know what I've done wrong, and I don't understand the error > > diagnostic (C2501) I'm getting from the (VS6.0) compiler. Please > > advise. TIA > > Post the shortest example that gives you that error, then post the > *exact* compiler diagnostic. Consider that while some of us may still > have VC6 lying around, it's likely that we don't have the ability to use > *that* old of a compiler to try your code. BTW, why don't you upgrade? 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 // error C2501: 'dbeZeroBibs' : missing storage-class or type specifiers // error C2040: 'dbeZeroBibs' : 'int' differs in levels of indirection from 'struct dbeBuild *' // error C2440: 'initializing' : cannot convert from 'struct dbeBuild *' to 'int' // This conversion requires a reinterpret_cast, a C-style cast or function-style cast // Error executing cl.exe. // dynarray.exe - 3 error(s), 0 warning(s) int main(int argc, char *argv[]) ////////// M A I N L I N E //////// { return 0; }
From: Thomas J. Gritzan on 30 Apr 2010 17:54 Am 30.04.2010 23:48, schrieb Mike Copeland: > 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 *' [...] -- Thomas
|
Next
|
Last
Pages: 1 2 Prev: initialize the pointer structure Next: Reversing 2nd order deep std::vector |