The error means that you have declared that a function exists and tried to use it, but you forgot to provide a definition. In this case, where have you defined your constructor?
I get that but this declaration Search(int size, int seed = 0) is kinda new to me. I've never seen a declaration that already had part of it defined (seed = 0). So would this translate into this:
1 2 3 4 5 6 7
Search(int size, int seed = 0)
//translate to
Search::Search(int size, int seed=0)
{
size = size;
}
The 2nd parameter there is called a default parameter. If, say you called Search(10, 10), size and seed will have the value 10 each. If you called Search(10), then size will have 10 and seed will have 0. Because we only provided one argument, seed will have that default value of 0.
Note defaults must be the rightmost:
1 2
Search::Search(int seed=0, int size) // error
Search::Search(int size, int seed = 0) // correct way
I get that but this declaration Search(int size, int seed = 0) is kinda new to me. I've never seen a declaration that already had part of it defined (seed = 0). So would this translate into this:
1 2 3 4 5 6 7
Search(int size, int seed = 0)
//translate to
Search::Search(int size, int seed=0)
{
size = size;
}
or is my process of thought way off base here?
No, only the declaration has the = 0 part, the definition can not have it or you get an error.
I'm running into this error:
Unhandled exception at 0x6e6e65ca (msvcr100d.dll) in search.exe: 0xC0000005: Access violation reading location 0xccccccc0.
and the compiler sends me off to here in the dbgdel.cpp:
1 2
/* verify block type */
_ASSERTE(_BLOCK_TYPE_IS_VALID(pHead->nBlockUse));
I'm clueless on compiler code(my university doesn't have us take a compiler building course till senior year).
So I just need set functions for the size and seed, in order to define the size() and seed()? This is all new to me and none of my profs so far have taught this type of coding.
Close, you're accidentally declaring a new variable called array that exists only in the constructor, rather than using the existing array member. Just remove the "double *" text that is in front of "array".
Hey thanks for the help on most of this. Do I need to declare anything for the size(size) and seed(seed)? Or would set_seed(int seed) work for seed and something similar work for size?
I'm working on my initialize_array(). Currently getting this error message:
Windows has triggered a breakpoint in search.exe.
This may be due to a corruption of the heap, which indicates a bug in search.exe or any of the DLLs it has loaded.
This may also be due to the user pressing F12 while search.exe has focus.
The output window may have more diagnostic information.
The source of the error is located somewhere in this function:
1 2 3 4 5 6 7 8 9 10
void Search::initialize_array()
{
int i=0;
srand(seed);
for(i; i<=getSize();i++)
{
double number = rand() % 1000;
array[i]=number; // I think it has something to do with this line
}
}