5 Replies - 412 Views - Last Post: 25 July 2012 - 05:07 PM Rate Topic: -----

#1 tranemone  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 26-June 12

Inheritance, with arguments in the parent class

Posted 25 July 2012 - 01:43 PM

I am trying to make a "Door" class inherit from a "Cell" class, but the cell class takes arguments. I really don't know where my problem is, I have tried looking at inheritance examples but they have not helped much.
header file
class Door : public Cell{
public:
    Door(int x, int y); }


I only have one error in the header file - "'Door' can not be defined in the result type a function"
.cpp file
Door::Door(int x, int y) : Cell(x,y) {}


I have three errors in the .cpp file
- "constructor can not have a return type"
- "use of undeclared identifier 'x'"
- "member 'Door' has the same name as its class"

Any help anyone can provide would be much appreciated, sorry, I know I am a noob. Thanks in advance for taking the time to at least read about my problem.

Is This A Good Question/Topic? 0
  • +

Replies To: Inheritance, with arguments in the parent class

#2 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 5928
  • View blog
  • Posts: 20,267
  • Joined: 05-May 12

Re: Inheritance, with arguments in the parent class

Posted 25 July 2012 - 02:02 PM

In your .cpp, did you remember to #include "Door.h"?

In your header file, did you remember to #include "Cell.h"?
Was This Post Helpful? 0
  • +
  • -

#3 tranemone  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 26-June 12

Re: Inheritance, with arguments in the parent class

Posted 25 July 2012 - 02:04 PM

View PostSkydiver, on 25 July 2012 - 02:02 PM, said:

In your .cpp, did you remember to #include "Door.h"?

In your header file, did you remember to #include "Cell.h"?


sorry, I forgot to say. I did include them. But thanks so much for your help.
Was This Post Helpful? 0
  • +
  • -

#4 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1852
  • View blog
  • Posts: 6,664
  • Joined: 19-February 09

Re: Inheritance, with arguments in the parent class

Posted 25 July 2012 - 03:06 PM

You need a semicolon at the end of the class definition.

class Door : public Cell {
public:
    Door(int x, int y); }; // <-- semicolon required


Was This Post Helpful? 1
  • +
  • -

#5 tranemone  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 26-June 12

Re: Inheritance, with arguments in the parent class

Posted 25 July 2012 - 04:40 PM

View Post#define, on 25 July 2012 - 03:06 PM, said:

You need a semicolon at the end of the class definition.

class Door : public Cell {
public:
    Door(int x, int y); }; // <-- semicolon required



Thank you so much that completely fixed all my errors.
Was This Post Helpful? 0
  • +
  • -

#6 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1852
  • View blog
  • Posts: 6,664
  • Joined: 19-February 09

Re: Inheritance, with arguments in the parent class

Posted 25 July 2012 - 05:07 PM

That's very good.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1