CFanatic

Go Back   CFanatic > Programming > C++ Programming

Join CFanatic Forum Now

Simple class not working topic posted under C++ Programming which is a part of Programming category in CFanatic Forum
Reply
 
Thread Tools Display Modes
  #1  
Old 01-07-2008, 11:45 PM
Junior Member
 
Join Date: Dec 2007
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
psppb is on a distinguished road
| More
Simple class not working

Hey all,

I am trying to figure this class thing out and still cannot get it right.
I keep on getting these errors which make no sense to me at all and even worse I am using a template right out of the book.

here is the code:
Code:
#include <iostream.h>
#include <string>

class dog
{
      private:
              
             
             
      public:
            void bark(void);
            void chasecar(void);
            void beg(void);
            dog();
};

//Constructor
dog::dog()
{

}        

void dog::bark(void)
{
     int x; 
     for(x= 0; x < 5; x++)
     {
           cout <<"Bark" << endl;
           }
          cout << "The squirrl ran away" <<endl;
          }
          
void dog::chasecar(void)
{
     int y; 
     for(y = 0; y < 5; y++)
     {
           cout << "Vroom!" << endl;
           }
         cout << "The dog must have got tired" << endl;
         }
         

void dog::beg(void)
{
     cout <<"Look at those eyes" << endl;
     }    
      
      
int main()
{
    
    
    dog harry();
    harry.bark(void);
    harry.beg(void);
    harry.chasecar(void);
    
    
    
     cin.ignore(256, '\n');
          cout << "Press ENTER to continue..." << endl;
          cin.get();
          return 0;
          }
I am going to try inserting a string to name the damn dog but that wasn't working at all because the compiler refused to recognize 'string' anywhere. I deleted it for now but still keep getting these errors I cannot fix.

55 C:\Documents and Settings\Bill\My Documents\class dog.cpp request for member `bark' in `harry', which is of non-class type `dog ()()'
55 C:\Documents and Settings\Bill\My Documents\class dog.cpp expected primary-expression before "void"
56 C:\Documents and Settings\Bill\My Documents\class dog.cpp request for member `beg' in `harry', which is of non-class type `dog ()()'
56 C:\Documents and Settings\Bill\My Documents\class dog.cpp expected primary-expression before "void"

every single function I use I get this error and I have no idea what's causing it

Thanks

Bill

Last edited by shabbir; 01-08-2008 at 01:08 AM. Reason: Code block
Reply With Quote
  #2  
Old 01-08-2008, 02:26 AM
Junior Member
 
Join Date: Aug 2007
Location: East Coast USA
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
HowardL is on a distinguished road
| More
Re: Simple class not working

I am using g++ in Fedora 4 linux. First of all, with this:
Code:
#include <iostream.h>
#include <string>
I got this:
Code:
#warning This file includes at least one deprecated or antiquated header. 
Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. 
Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> 
instead of the deprecated header <iostream.h>.
I have been learning to use this:
Code:
#include <iostream>
#include <string>
using namespace std;
Which took care of that.
Then I got it to compile with the following changes:
Code:
int main()
{
  dog harry;      // dog harry();    It seemed to me that here you
                  // should be declaring a class, not calling function
  harry.bark();      // harry.bark(void);
  harry.beg();       // harry.beg(void);
  harry.chasecar();  // harry.chasecar(void);
. . . . .
...and a run gave me this:
Code:
$   ./psppb1
Bark
Bark
Bark
Bark
Bark
The squirrl ran away
Look at those eyes
Vroom!
Vroom!
Vroom!
Vroom!
Vroom!
The dog must have got tired
Press ENTER to continue...
If that came directly from the book, it wasn't edited very well was it... or is it old

Last edited by HowardL; 01-08-2008 at 02:29 AM.
Reply With Quote
  #3  
Old 01-08-2008, 06:26 PM
Junior Member
 
Join Date: Dec 2007
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
psppb is on a distinguished road
| More
Re: Simple class not working

Hey thanks for the reply! I got it to work using
Code:
int main()
{
    
    
    dog harry;
    harry.bark();
    harry.beg();
    harry.chasecar();
    
    
    
     cin.ignore(256, '\n');
          cout << "Press ENTER to continue..." << endl;
          cin.get();
          return 0;
          }
it wasn't from the book I was playing around with the book format. I am just trying to figure the concept of class out. I am using Dev C++ for windows but I do run debian linux on this machine as well.

Thanks again!

Bill

Last edited by shabbir; 01-08-2008 at 10:23 PM. Reason: Code Block
Reply With Quote
  #4  
Old 01-08-2008, 10:24 PM
shabbir's Avatar
Administrator
 
Join Date: Sep 2006
Posts: 1,158
Thanks: 48
Thanked 62 Times in 43 Posts
shabbir has a spectacular aura aboutshabbir has a spectacular aura about
| More
Re: Simple class not working

Please use the code block when you have code snippets in posts
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Command Line Compile + Subdirectory DLL Not Working? will C# Programming 1 10-18-2008 09:41 PM
get Class johny10151981 Win32 Programming 1 10-07-2008 03:58 AM
C# and XML simple problem lkytmr C# Programming 1 04-14-2008 02:19 PM
Simple encryption program Trebbert Win32 Programming 0 09-23-2007 04:09 AM
working of memset() function sureshN C Programming 3 05-28-2007 04:42 AM

 

Advertisement

CFanatic Search
Custom Search

Advertisement

All times are GMT -5. The time now is 03:33 PM.



Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO ©2010, Crawlability, Inc.
Cfanatic.com is a premier member of the IDG TechNetwork. For advertising opportunities contact here
Get Paid for Working on Projects Matching Your Expertise at Go4Expert's Jobs Board