Good evening,
I have been working with derived classes and what could seem like an easy problem has had me look into it for hours.
My error message:
Square.h(14) : error C2512: 'Rectangle' : no appropriate default constructor available
Everything works well if I don't use my derived class "Square.h" but I soon as I try, then I get that constructor error. IF someone could please help me I would greatly appreciate it :)
Thank you,
John
My code:
The base class:
#pragma once
ref class Rectangle
{
public:
int m_Left;
int m_Top;
int m_Right;
int m_Bottom;
Rectangle(int lt, int tp, int rt, int bm)
{
m_Left = lt;
m_Top = tp;
m_Right = rt;
m_Bottom = bm;
}
//Defining the property for obtaining the LeftValue
property int lt
{
int get()
{
return m_Left;
}
void set(int value) { m_Left = value; }
}
//Defining the property for obtaining the TopValue
property int tp
{
int get()
{
return m_Top;
}
void set(int value) {m_Top = value;}
}
//Defining the property for obtaining the RightValue
property int rt
{
int get()
{
return m_Right;
}
void set(int value) {m_Right = value;}
}
//Defining the property for obtaining the BottomValue
property int bm
{
int get()
{
return m_Bottom;
}
void set(int value) {m_Bottom = value;}
}
};
My derived class:
#pragma once
#include <iostream> // For stream I/O
#include <cstring>
#include "Rectangle.h"
ref class CSquare: Rectangle
{
public:
int m_Left;
int m_Top;
int m_Right;
int m_Bottom;
CSquare(int lt, int tp, int rt, int bm)
{
m_Left = lt;
m_Top = tp;
m_Right = rt;
m_Bottom = bm;
}
//LEft value function
long LeftValueS()
{
return (m_Left);
}
//top function value
long TopValueS()
{
return (m_Top);
}
};
My CPP file:
// TestingSquare.cpp : main project file.
#include <iostream>
#include <cstring>
#include "stdafx.h"
#include "Rectangle.h"
#include "Square.h"
using namespace System;
int main()
{
Rectangle^ Rect1 = gcnew Rectangle(11,22,33,44);
//Rect values displayed
Console::WriteLine("Rect LeftValue:{0}",Rect1->lt);
Console::WriteLine("Rect TopValue:{0}",Rect1->tp);
Console::WriteLine("Rect RightValue:{0}",Rect1->rt);
Console::WriteLine("Rect BottomValue:{0}",Rect1->bm);
//Square values displayed
/*CSquare Square(5,5,5,5);
Console::WriteLine("Square Left value:{0}",Square.LeftValueS());
Console::WriteLine("Square top value:{0}",Square.TopValueS());*/
return 0;
}