10 Replies - 1099 Views - Last Post: 16 September 2011 - 04:30 PM Rate Topic: -----

#1 Twoods196  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 73
  • Joined: 21-April 09

which is of non-class type Help

Posted 15 September 2011 - 08:06 PM

Hey Guys, I have some code that is driving me insane. I keeps throwing the following error:

main.cpp: In function ‚int main()‚:
main.cpp:12: error: request for member ‚dispBook‚ in ‚book1‚, which is of non-class type ‚Book ()()‚


and I cant not find out for the life of me why. I beleive I have all my -> correct so that shouldnt be the problem. Here is my code:

lab04.cpp
#include"lab04.h"

Book::Book()
{
        title = "";
        author = "unknown";
        int price = 795;
        genre = 0;
        status = false;
}

Book::Book(string title, int price)
{
        this->title = title;
        this->price = price;
        author = "unknown";
        genre = 0;
        status = false;
}



void Book::dispBook(void) const
    {
    cout.setf(ios::fixed | ios::showpoint);
    cout.precision(2);

    cout << "Title   : \"" << title << "\"\n"
         << "Author  : \"" << author << "\"\n"
         << "Price   : $" << price / 100.0 << endl
         << "Genre   : " << genre
         << "In stock? " << (status ? "yes" : "no")
         << endl;
    return;
    }


main.cpp
#include<iostream>
#include<string>
#include"lab04.h"
using namespace std;

int main()
{
        string title = "The art of Wooting";
        int price = 203;
        Book book1;
        Book book2(title,price);
        book1.dispBook();
        book2.dispBook();

		system("pause");
		return 0;
}


Lab04.h
#ifndef LAB04_H
#define LAB04_H
#include<iostream>
#include<string>
using namespace std;

class Book
{

public:
        Book();
        Book(string,int);
        void dispBook(void) const;
private:
        string title;
        string author;
		int price;
        int genre;
        bool status;
};
#endif



any help is greatly appreciated as im starting to get sore eyes lol Thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: which is of non-class type Help

#2 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3089
  • View blog
  • Posts: 19,137
  • Joined: 14-September 07

Re: which is of non-class type Help

Posted 15 September 2011 - 08:14 PM

You're re declaring/defining price in the no arg constructor [line 7].
Was This Post Helpful? 0
  • +
  • -

#3 Twoods196  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 73
  • Joined: 21-April 09

Re: which is of non-class type Help

Posted 15 September 2011 - 08:24 PM

if your referring too

Book::Book()
{
        title = "";
        author = "unknown";
        int price = 795;
        genre = 0;
        status = false;
}




I had the int price there just as a test. If not, im not sure what u mean
Was This Post Helpful? 0
  • +
  • -

#4 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1276
  • View blog
  • Posts: 4,401
  • Joined: 19-February 09

Re: which is of non-class type Help

Posted 15 September 2011 - 08:49 PM

It runs ok for me. Maybe try taking void out of dispBook().
Was This Post Helpful? 0
  • +
  • -

#5 Twoods196  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 73
  • Joined: 21-April 09

Re: which is of non-class type Help

Posted 15 September 2011 - 09:10 PM

Thats the thing, it works fine in Visual Studio but our teacher is making us do it in linux with VIM. It gives those errors in there.
Was This Post Helpful? 0
  • +
  • -

#6 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1276
  • View blog
  • Posts: 4,401
  • Joined: 19-February 09

Re: which is of non-class type Help

Posted 15 September 2011 - 09:23 PM

Did you copy the text files over? Text files are slightly different in Linux and Windows.
Was This Post Helpful? 0
  • +
  • -

#7 Twoods196  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 73
  • Joined: 21-April 09

Re: which is of non-class type Help

Posted 15 September 2011 - 09:54 PM

Yes I copied it over, but I see no diffrence in the 2
Was This Post Helpful? 0
  • +
  • -

#8 PlasticineGuy  Icon User is offline

  • mov dword[esp+eax],0
  • member icon

Reputation: 281
  • View blog
  • Posts: 1,436
  • Joined: 03-January 10

Re: which is of non-class type Help

Posted 15 September 2011 - 11:32 PM

This error would normally happen if you do:
Book book1();
This looks like a function declaration to the compiler and so book1 becomes a function pointer, not an object. However, I'm not sure why this should be the case with your current code.
Is this your exact code? Have you edited it in any way?

Try making a brand new project, copy and paste the code and see what happens.
Was This Post Helpful? 1
  • +
  • -

#9 Twoods196  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 73
  • Joined: 21-April 09

Re: which is of non-class type Help

Posted 16 September 2011 - 11:39 AM

Yes its the exact code, an orginally I had the Book book1() and changed it. But it still throws the error
Was This Post Helpful? 0
  • +
  • -

#10 Mina-kun  Icon User is offline

  • New D.I.C Head

Reputation: 20
  • View blog
  • Posts: 43
  • Joined: 13-September 11

Re: which is of non-class type Help

Posted 16 September 2011 - 03:03 PM

What command are you using to compile? Are you absolutely sure that Book.cpp is being linked with the executable? Since nothing else seems to be the cause of the issue (including line endings), it might be worth a check.
Was This Post Helpful? 0
  • +
  • -

#11 jimblumberg  Icon User is offline

  • member icon


Reputation: 3846
  • View blog
  • Posts: 11,775
  • Joined: 25-December 09

Re: which is of non-class type Help

Posted 16 September 2011 - 04:30 PM

If you comment out line 12 does the program compile? Are you using the command line to compile the program or an IDE. If an IDE which one? If not then show the complete compile command.

The code posted in post #1 compiles fine for me on Linux. So if it still doesn't compile for you, please use the full editor and attach the actual files.

Jim

This post has been edited by jimblumberg: 16 September 2011 - 04:33 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1