when compiling code from my main function ireceive the following error
error: conversion from 'rectangle*' to non0scalar type 'rectangle' requested
My code is quite simple;
Here's my main function

#include <iostream>
#inclde "rectangle.h"
using namespace std;
int main()
    rectangle rect = new rectangle(3,4);



    return 0;

here's my class

#ifndef RECTAGLE_H
#define RECTAGLE_H
#include <iostream>
#include <cmath>
using namespace std;
class rectangle{
    int length, width;
    rectangle(int x, int y){
        length = x;
        width = y;};
    int area()
        int a = length*width;
        return a;
    int perimeter()
        int b = 2*length*width;
        return b;
    double diagonal()
        int c = sqrt(length*length + width*width);
        return c;
#endif // RECTAGLE_H

The biggest problem with the code here (apart from the spelling mistake on line 2 of the header file) is that you're creating a pointer-to-a-rectangle like this (remember that new creates an object on the heap memory, and gives back a pointer to that object):

new rectangle(3,4);

and then you're trying to assign that pointer-to-a-reactangle to something that is not a pointer:

rectangle rect = new rectangle(3,4);

The object on the left, named rect, is a rectangle object. The object on the right, that has no name, is a pointer-to-a-rectangle. These are different kinds of objects and you cannot assign one to the other.

There is no need here to use new. The simple fix is to change line 6 to:
rectangle rect(3,4);
This will create a rectangle object, named rect, using the constructor you wrote.

There is another problem. You said that you would wriet the destructor. You promised that when you wrote this in the header:
But you didn't write it. This is a simple object and the default destructor will be fine here. Remove your promise to write the destructor.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.