C++ Basic Classes

This is a really simple program but for the life of me i do not know why it is not working. When trying to compile I recieve these errors.
‘int main()’:
main.cpp:9:11: error: no matching function for call to ‘GenShape::GenShape()’
main.cpp:9: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

//My main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include "GenShape.h"

using namespace std;

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

//My .cpp File
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include"GenShape.h"
#include<iostream>

using namespace std;

GenShape:: GenShape(int p)
{
  perimeter = p;
}

void GenShape:: setPerimeter( int perimeter ) //try perimeter instead of GenShape
{
}

int GenShape:: getPerimeter() const
{
  return perimeter;
  
}

void GenShape:: printPerimeter() const
{

  cout<<"Perimeter is "<<getPerimeter()<<endl;
}

//MY header file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#ifndef GEN_H
#define GEN_H

#include <iostream>

using namespace std;

class GenShape //Base Class
{
	private:
		int perimeter;
	
	public:
		GenShape();
		GenShape(int p);
		~GenShape();
		
		int getPerimeter() const;
		void setPerimeter(int p);
		
		void printPerimeter() const;
};

#endif 
You forgot to define the default constructor GenShape::GenShape() in the cpp module.
Last edited on
Ah man, new it was something silly! Thank you Vlad!
Topic archived. No new replies allowed.