Classes and inheritance

I am Really new to c++ and intimidated. MY class is returning errors and i do not know why? I think my header files are correct but my .cpp files i am struggling with.
//This is my base class header file.How should the GenShape.cpp file look?
Please Help I am dying!!
[code]
class GenShape //Base Class
{
private:
int perimeter;

public:
GenShape();
GenShape(int p);
~GenShape();

int getPerimeter() const;
void setPerimeter(int p);

void printPerimeter() const;
};
[code]
closed account (28poGNh0)
Your code is fine maybe if you put the whole of it,or at lest show us those errors.
Last edited on
Sorry Techno here they are...

main.cpp: In function ‘int main()’:
main.cpp:10:11: error: no matching function for call to ‘GenShape::GenShape()’
main.cpp:10:11: note: candidates are:
In file included from main.cpp:1:0:
GenShape.h:15:3: note: GenShape::GenShape(int)
GenShape.h:15:3: note: candidate expects 1 argument, 0 provided
GenShape.h:8:7: note: GenShape::GenShape(const GenShape&)
GenShape.h:8:7: note: candidate expects 1 argument, 0 provided
make: *** [main.o] Error 1

//my main file is
1
2
3
4
5
6
7
8
9
10
11
12
13
14
int main()
{ 

  
	cout << "-- Generic Shape Information --" << endl;
	
	GenShape gen;
	gen.printPerimeter();
	
	gen.setPerimeter(20);
	gen.printPerimeter();
	
	return 0;
}
¿again? http://www.cplusplus.com/forum/beginner/108334/

The problem is that you are lying, that is not the code that you are compiling.
What the hell man? Why would I Lie, Its Pointless. I tried adding a default constructor, Go to that thread and tell me did I mark it as solved? Did I say anywhere Solved?

And yea the difference is i added the cpp file there which doesnt work , or maybe you dont know the difference between a cpp file and an h file?
Last edited on
The below code builds without error. Note that all I did was copy/paste your example and give your GenShape functions dummy bodies:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// header.h
class GenShape //Base Class
{
private:
    int perimeter;

public:
    GenShape() {}
    GenShape(int p) {}
    ~GenShape() {}

    int getPerimeter() const {return 0;}
    void setPerimeter(int p) {}

    void printPerimeter() const {}
};
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//main.cpp
#include <iostream>
#include "header.h"

using namespace std;

int main()
{
	cout << "-- Generic Shape Information --" << endl;
	
	GenShape gen;
	gen.printPerimeter();
	
	gen.setPerimeter(20);
	gen.printPerimeter();
	
	return 0;
}


So while I wouldn't say you are lying... ne555 is correct in that this is not the code you are compiling. Because if it were, you would not be getting this error.

What's probably happening is you are not compiling the code you think you are. This can be caused by a few things.

1) Maybe your IDE screwed up and is hanging onto old cached files. Do a clean and/or rebuild

2) Maybe you have multiple header files, and you are #including an outdated one. If your IDE allows, right click on the #include line and say "open file". Check the path of that file and make sure it's the file you want.


probably some other stuff could cause it too, but that's all I can think of at the moment.
Last edited on
Thank you very much Disch! I did manage to fix the fault by just restarting my ide, it had its period! Enjoy your day further!
Topic archived. No new replies allowed.