The variable 'idata' is being used without being initialized.
Aug 16, 2011 at 11:52am UTC
i am trying to input data into a linked list, the instance of the list is called myList and the data i want to input is idata. ProceedingsBook is the class for the data i want to store.
I have this code to input the data:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
proceedingsBook *idata;
string tmpString;
int tmpInt;
if (inputBookType = 1)
{
cout<<"enter the publisher:" <<endl;
cin>>tmpString;
idata->setPublisher(tmpString);
tmpString = "" ;
cout<<"enter the ISBN number (13 char):" <<endl;
cin>>tmpInt;
idata->setIsbn(tmpInt);
tmpInt = NULL;
cout<<"enter the title:" <<endl;
cin>>tmpString;
idata->setTitle(tmpString);
tmpString = "" ;
cout<<"enter the Author:" <<endl;
cin>>tmpString;
idata->setAuthor(tmpString);
tmpString = "" ;
myList.addToList(idata);
}
However i get a break/continue error on line 8 saying:
Run-Time Check Failure #3 - The variable 'idata' is being used without being initialized
When i have initialized it directly above, i dont understand why this error has come up, any help would be much appreciated, thanks
Last edited on Aug 16, 2011 at 12:01pm UTC
Aug 16, 2011 at 12:02pm UTC
copy/paste the class declaration of proceedingsBook
perhaps you missed something in the constructor and you're using it in your main?
Aug 16, 2011 at 12:02pm UTC
When i have initialized it directly above
You have? Where?
Aug 16, 2011 at 12:03pm UTC
You haven't initialised idata. You've only declared it. That allocates some space for it somewhere (on the stack in this case), but you've not given it an initial value.
Aug 16, 2011 at 12:10pm UTC
your right i had only declared it, but what can i initialize it to if i just want it empty, i tried NULL but that throws up "Access violation" errors.
Here is my preceedings book class, it inherits from publication:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
class Publication {
private :
string publisher;
int isbn;
public :
string getPublisher();
int getIsbn();
void setPublisher(string value);
void setIsbn(int value);
};
class Book:public Publication{
private :
string title;
string author;
public :
string getTitle();
string getAuthor();
void setTitle(string value);
void setAuthor(string value);
};
class proceedingsBook:public Book{
private :
string editor;
string date;
public :
string getEditor();
string getDate();
void setEditor(string value);
void setDate(string value);
};
Aug 16, 2011 at 1:24pm UTC
it just needed a idata = new proceedingsBook;
Topic archived. No new replies allowed.