Thread: problem with c++ classes

  1. #1
    Registered User
    Join Date
    Oct 2003
    Posts
    27

    problem with c++ classes

    Can anyone tell me what is wrong with this....I keep getting one error about ..
    'initializing' : cannot convert from 'Book ** ' to 'Book *[]'
    Any help would be appreciated....

    [code]
    //class Book
    #pragma once
    #include "iomanip"
    #include <iostream>
    #include <string>
    #using <mscorlib.dll>

    using namespace System;
    using namespace std;

    class Book
    {
    private:
    int m_Bnumb;
    float m_Bprice;
    string m_Bauthor;
    string m_Bname;
    int m_Bquant;


    public:
    Book(void);
    void Dispose();
    int main_menu();
    void m_update(int, float, string, string, int);
    void m_display();
    void m_dispord(int);
    float m_total();
    };

    //.cpp
    #include "StdAfx.h"
    #include "iomanip"
    #include "conio.h"
    #include "ctype.h"
    #include <string>
    #include "Book.h"
    #include <iostream>

    #using <mscorlib.dll>
    using namespace System;
    using namespace std;

    Book::Book(void)
    {
    m_Bnumb = 0;
    m_Bprice = 0;
    /* m_Bauthor =;
    m_Bname = ;*/
    m_Bquant = 0;

    }
    void Book:ispose()
    {
    }


    void Book::m_update(int Bnumb, float Bprice, string Bauthor, string Bname, int Bquant)
    {
    m_Bnumb = Bnumb;
    m_Bprice = Bprice;
    m_Bauthor =Bauthor;
    m_Bname = Bname;
    m_Bquant = Bquant;
    }

    void Book::m_display()
    {
    cout << m_Bnumb << endl;
    cout << m_Bprice << endl;
    cout << m_Bauthor << endl;
    cout << m_Bname << endl;
    cout << m_Bquant << endl;



    }
    void Book::m_dispord(int qty)
    {
    if ( m_Bquant < qty)
    {
    m_display();
    }
    }


    float Book::m_total()
    {
    return m_Bprice * m_Bquant;
    }

    //program
    #include "StdAfx.h"
    #include "iomanip"
    #include "ctype.h"
    #include "conio.h"
    #include "Book.h"
    #include <iostream>
    #include <string>
    #using <mscorlib.dll>

    using namespace System;
    using namespace std;

    void inputdata(Book*, int&);
    void printall(Book* , int );
    void printord(Book* , int );
    int main_menu();

    int main()
    {
    cout << setiosflags(ios::fixed)
    << setiosflags(ios::showpoint)
    <<setprecision(2);

    const MAX = 20;
    int ctr = 0;
    int menunumb;

    (ERROR) Book* MyBook[] = new Book*[MAX];


    while (menunumb != 5)
    {
    menunumb = main_menu();
    switch(menunumb)
    {
    case 1:

    break;
    case 2:

    break;
    case 3:

    break;
    case 4:

    break;
    default:
    {
    cout << "Invalid Entry" << endl;
    system("pause");
    }
    }
    }




    //inputdata(MyBook[], ctr);
    //printall(MyBook[], ctr);
    //printord(MyBook[], ctr);

    return 0;
    }

    int main_menu()
    {
    int menunumb;

    system("cls");

    cout << "Main Menu" << endl; //menu for user to choose an option
    cout << endl;
    cout << "Select an option..." << endl;
    cout << endl;
    cout << "1. Enter Information" << endl;
    cout << "2. Update Information" << endl;
    cout << "3. Display Information" << endl;
    cout << "4. Calculate Information" << endl;
    cout << "5. Exit" << endl;
    cout << endl;
    cin >> menunumb;
    return menunumb;




    }

    void inputdata(Book* MyBook[], int& ctr)
    {
    int Bnumb;
    float Bprice;
    string Bauthor;
    string Bname;
    int Bquant;
    char contin = 'Y';
    while (contin == 'Y' || contin == 'y')
    {

    cout << "Enter Book Title: " << endl;
    cin >> Bname;
    cout << "Enter Book Author: " << endl;
    cin >> Bauthor;
    cout << "Enter Book Number: " << endl;
    cin >> Bnumb;
    cout << "Enter Book Price: " << endl;
    cin >> Bprice;
    cout << "Enter Book Quantity: " << endl;
    cin >> Bquant;

    MyBook[ctr]->m_update(Bnumb, Bprice, Bauthor, Bname, Bquant);
    ctr++;
    cout << "Again? (Y/N): ";
    cin >> contin;
    }
    return;
    }

    void printall(Book* MyBook[], int ctr)
    {

    for( int count = 0; count <= ctr; count++)
    {

    MyBook[count]->m_display();

    }

    }
    void printord(Book* MyBook[], int ctr)
    {
    int qty;

    cout << "Min order quantity: " << endl;
    cin >> qty;

    for( int count = 0; count <= ctr; count++)
    {
    Last edited by student2005; 11-13-2003 at 05:04 PM.

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981

  3. #3
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    You could start by specifying the line number for the code which causes the error.
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  4. #4
    Registered User Dante Shamest's Avatar
    Join Date
    Apr 2003
    Posts
    970
    A quick glance through your code suggests that this line

    Code:
     Book* MyBook[] = new Book*[MAX];
    should be

    Code:
    Book** MyBook[] = new Book*[MAX] ;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. problem with classes and pointers
    By Akkernight in forum C++ Programming
    Replies: 18
    Last Post: 02-21-2009, 06:21 AM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Having a problem with Classes
    By FoxTrot in forum C++ Programming
    Replies: 10
    Last Post: 09-06-2007, 07:40 PM
  4. Problem with destructors.
    By Hulag in forum C++ Programming
    Replies: 7
    Last Post: 06-11-2004, 12:30 PM
  5. problem w/ nested templatized classes
    By *ClownPimp* in forum C++ Programming
    Replies: 8
    Last Post: 10-19-2002, 07:58 AM