Thread: Declaring enumerated data type

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Nov 2020
    Posts
    2

    Declaring enumerated data type

    I'm asked to create a SortType enumerated data type that stores two values, BY_TITLE and BY_YEAR. I'm then trying to implement a void addBookToList(SortType s, ListType *list, BookType *b) function that finds the new book’s correct insertion point in the list, based on the sort type indicated in the s parameter.

    If the sort type is BY_TITLE, the book must be inserted in alphabetical order by title, and if the sort type is BY_YEAR, the book must be inserted in ascending order by year.

    When I try to create the addBookToList function I keep getting the error:

    expected declaration specifiers or ‘...’ before ‘SortType’ void addBookToList(SortType s, ListType *list, BookType *b)

    I'm not sure if I'm declaring my SortType data type correctly and would appreciate some help.

    defs.h:
    Code:
    enum sort{
        BY_TITLE,
        BY_YEAR
    } SortType;
    
    book.c
    Code:
    void addBookToList(SortType s, ListType *list, BookType *b){
        if(s == BY_TITLE){
        }
        if(s == BY_YEAR){
        }
    }
    
    I tried just changing the data structure in defs.h to:
    Code:
    enum SortType{
        BY_TITLE,
        BY_YEAR
    };
    and the error changed to 'unknown type name 'SortType'; did you mean 'ListType'? void addBookToList(SortType s, ListType *list, BookType *b)
    Last edited by marystew; 11-08-2020 at 11:11 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with enumerated data types.
    By And3rs in forum C++ Programming
    Replies: 4
    Last Post: 10-05-2008, 10:06 AM
  2. declaring data type
    By sarathius in forum C Programming
    Replies: 4
    Last Post: 04-17-2008, 04:54 AM
  3. 2-dimesional Array w/ enumerated type
    By partnole in forum C++ Programming
    Replies: 1
    Last Post: 06-02-2007, 01:22 PM
  4. enumerated type and lvalue missing
    By baniakjr in forum C++ Programming
    Replies: 6
    Last Post: 11-22-2006, 07:06 AM
  5. Using enumerated data types
    By SXO in forum C++ Programming
    Replies: 7
    Last Post: 09-04-2001, 06:26 PM

Tags for this Thread