PDA

View Full Version : request for member which is of non-class type


surreal5335
07-14-2010, 06:47 AM
I am getting the following errors in my code:


week5-6Prog.cpp: In function `int main()':
week5-6Prog.cpp:65: error: request for member `Insert' in `book', which is of no
n-class type `ABook ()()'
week5-6Prog.cpp:66: error: request for member `SortedInsert' in `book', which is
of non-class type `ABook ()()'
week5-6Prog.cpp:67: error: request for member `SortedInsert' in `book', which is
of non-class type `ABook ()()'
week5-6Prog.cpp:68: error: request for member `SortedInsert' in `book', which is
of non-class type `ABook ()()'


so basically I am trying to create an object so as to use methods in a class.

Here is my code setup:


class ABook {
public:

string removedItem;

ABook(); // default constructor
~ABook(); // deconstructor Removes all elements from the list.
void ABook::Insert(string NewItem);
void ABook::SortedInsert(string NewItem);
string ABook::Remove(string& item);

private:
//AddressNode * topPtr; // Should be a pointer to the top of the list.
}; // end class

void ABook::Insert(string NewItem) {
//Add item to the Linked List
cout << NewItem << "\n";
}

///////////////////////////////////// main method ///////////////////////

int main() {

ABook book();


book.Insert("Precious"); //- Insert Precious into list.


system("PAUSE");

} // end main




This same setup has worked for me in the past. why not now?

oracleguy
07-14-2010, 07:44 PM
I am getting the following errors in my code:



so basically I am trying to create an object so as to use methods in a class.

Here is my code setup:


class ABook {
public:

string removedItem;

ABook(); // default constructor
~ABook(); // deconstructor Removes all elements from the list.
void ABook::Insert(string NewItem);
void ABook::SortedInsert(string NewItem);
string ABook::Remove(string& item);

private:
//AddressNode * topPtr; // Should be a pointer to the top of the list.
}; // end class

void ABook::Insert(string NewItem) {
//Add item to the Linked List
cout << NewItem << "\n";
}

///////////////////////////////////// main method ///////////////////////

int main() {

ABook book;


book.Insert("Precious"); //- Insert Precious into list.


system("PAUSE");

} // end main




This same setup has worked for me in the past. why not now?

See my changes in red. When you declare a class and want to use the default constructor, you don't need the parenthesis.