c++ error: must point to class/struct

error C2227: left of '->ribike' must point to class/struct

Page 1 of 1

5 Replies - 2984 Views - Last Post: 21 August 2010 - 03:19 AM Rate Topic: -----

#1 bestsun  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 18-January 10

c++ error: must point to class/struct

Posted 20 August 2010 - 10:42 PM

/************ People.h*************************/

#ifndef _People_h_

#define _People_h_


class Bike;
class People
{
	public:
		People();
	    ~People();
		void ride();
		void Setresouce(Bike*a);
	private:
		Bike *b;
	
};

#endif 




/************People.cpp*****************/


#include"People.h"
#include<iostream>

People::People()
{
	b=NULL;
}
People::~People()
{
}
void People::Setresouce(Bike *a)
{
	b=a;
	
}
void People::ride()
{
	
      b->ribike();                    [color="#00FF00"][size="5"]/************Here  is the problem:
                                   1)error C2027: use of undefinedtype 'Bike' see declaration of 'Bike'
                                   2)error C2227: left of '->ribike' must point to class/struct/union 
                                     *********************/[/size][/color]


/***************Bike.h  **************************/

#ifndef _Bike_h_

#define _Bike_h_

class Bike
{
public:
	Bike();
	~Bike();
	void ribike();

}; 
#endif 

/*************Bike.cpp*****************/
#include"Bike.h"
#include<iostream>
using namespace std;

Bike::Bike()
{
}
Bike::~Bike()
{

}
void Bike::ribike()
{
	cout<<"bike is riding"<<endl;
}


error C2227: left of '->ribike' must point to class/struct

MOD EDIT: Moved "question" from subtitle to post.

This post has been edited by JackOfAllTrades: 21 August 2010 - 04:06 AM


Is This A Good Question/Topic? 0
  • +

Replies To: c++ error: must point to class/struct

#2 BigDinTheMornin  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 56
  • Joined: 21-June 09

Re: c++ error: must point to class/struct

Posted 20 August 2010 - 10:49 PM

First and foremost what are you trying to accomplish? You have posted code onto here and expect us to know automatically how it functions. Tell us what your program does, the errors which I clearly see stated in Green, and how you are trying to go about solving your problem. I would be glad to assist you afterwards.

P.S. Include code in this format
   //CODE HERE  

Was This Post Helpful? 0
  • +
  • -

#3 bestsun  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 18-January 10

Re: c++ error: must point to class/struct

Posted 20 August 2010 - 11:08 PM

View PostBigDinTheMornin, on 20 August 2010 - 09:49 PM, said:

First and foremost what are you trying to accomplish? You have posted code onto here and expect us to know automatically how it functions. Tell us what your program does, the errors which I clearly see stated in Green, and how you are trying to go about solving your problem. I would be glad to assist you afterwards.

P.S. Include code in this format
   //CODE HERE  

I want to call ribike(); with b->.
how can i do
thanks
Was This Post Helpful? 0
  • +
  • -

#4 demosthenes2k8  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 93
  • Joined: 30-December 09

Re: c++ error: must point to class/struct

Posted 20 August 2010 - 11:46 PM

In People.h you say that the bike class exists...but you don't have the actual contents of the class. You have to #include "bike.h" in "People.h"
Was This Post Helpful? 0
  • +
  • -

#5 bestsun  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 18-January 10

Re: c++ error: must point to class/struct

Posted 21 August 2010 - 01:23 AM

View Postdemosthenes2k8, on 20 August 2010 - 10:46 PM, said:

In People.h you say that the bike class exists...but you don't have the actual contents of the class. You have to #include "bike.h" in "People.h"

Thanks! you are right!
but i want to ask you whether i must put " #include "bike.h" in "People.h" " in "People.h"?
you see i also declear " class Bike " in front of the "class People" in the People.h!
Was This Post Helpful? 0
  • +
  • -

#6 guahguahmonster  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 68
  • View blog
  • Posts: 209
  • Joined: 29-August 07

Re: c++ error: must point to class/struct

Posted 21 August 2010 - 03:19 AM

What you did when you declared "class Bike" is a forward declaration. The simplified rule is that you can use this when you only have a pointer or a reference to a Bike in a Person. But in this case, in your Person class you have a function that calls ribike(), a function of a Bike. That means the compiler needs to know about that function--your forward declaration is insufficient because it's not a complete declaration. You must declare the function, and you do so by including "bike.h"

This post has been edited by guahguahmonster: 21 August 2010 - 03:32 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1