Konstruktor fehler
-
Hallo, ich vermute das ich einen Fehler im Konstruktor für Schalter habe. Leider finde ich ihn nicht mit der Fehlerausgabe kann ich leider nichts anfangen da mir der Compiler nur "Debug Assertion failed" sagt. Vllt. sieht ihn einer von euch.
Schalter.h
#ifndef _Schalter_ #define _Schalter_ #include "TextBox.h" class Schalter { private: int nX, nY; int fEin; TextBox *pTxEin, *pTxAus, *pTxZust; public: int GetX(); int GetY(); int GetZust(); void SetX(int X); void SetY(int Y); void SetZust(int Zust); Schalter(); Schalter(char *Ein, char *Aus, int X, int Y); Schalter(const Schalter &s); ~Schalter(); void Set(const Schalter &s); void Show(); }; #endifTextBox.h
#ifndef _TextBox_ #define _TextBox_ class TextBox { private: int nX, nY; int nW, nH; char *szText; public: int GetX() const; int GetY() const; int GetW() const; int GetH() const; const char * GetText() const; void SetX(int X); void SetY(int Y); void SetW(int W); void SetH(int H); void SetText(char *Text); TextBox(char *Text, int X, int Y, int W, int H); TextBox(const TextBox &t); ~TextBox(); void Show(); int Contains(int nX, int nY); }; #endifWindows.h
#ifndef __WINADAPT #define __WINADAPT #include "windows.h" extern void Line(int xa, int ya, int xe, int ye); extern void Text(int xa, int ya, char txt[]); extern void Rect(int xa, int ya, int xe, int ye); extern void Elli(int xa, int ya, int xe, int ye); extern void LineCol(int r, int g, int b); extern void FillCol(int r, int g, int b); extern void PutPixel(int xa, int ya, COLORREF crColora); extern void FillPoly(int *lpPoint, int nPoints); #endifSchalter.cpp
#include "TextBox.h" #include "Schalter.h" #include "Winadapt.h" #define Abstand 30 int Schalter::GetX() { return Schalter::nX; } int Schalter::GetY() { return Schalter::nY; } int Schalter::GetZust() { return Schalter::fEin; } void Schalter::SetX(int X) { nX = X; pTxEin->SetX(X); pTxAus->SetX(X+Abstand); pTxZust->SetX(X+2*Abstand); } void Schalter::SetY(int Y) { nY =Y; pTxEin->SetY(Y); pTxAus->SetY(Y); pTxZust->SetY(Y); } void Schalter::SetZust(int Zust) { Schalter::fEin = Zust; if(Zust == 1) pTxZust->SetText("1"); pTxZust->SetText("0"); } Schalter::Schalter() { nX = 0; nY = 0; fEin = 0; } Schalter::Schalter(char *Ein, char *Aus, int X, int Y) { nX = X; nY = Y; pTxEin = new TextBox("Ein", X, Y, Abstand, Abstand); pTxAus = new TextBox("Aus", X+Abstand, Y, Abstand, Abstand); pTxZust = new TextBox("", X+2*Abstand, Y, Abstand, Abstand); SetZust(0); } Schalter::Schalter(const Schalter &s) { pTxEin = new TextBox (*s. pTxEin ); pTxAus = new TextBox (*s. pTxAus ); pTxZust = new TextBox (*s. pTxZust ); } Schalter::~Schalter() { delete[] pTxEin; delete[] pTxAus; delete[] pTxZust; } void Schalter::Set(const Schalter &s) { delete[] pTxEin; delete[] pTxAus; delete[] pTxZust; pTxEin = new TextBox (*s. pTxEin ); pTxAus = new TextBox (*s. pTxAus ); pTxZust = new TextBox (*s. pTxZust ); } void Schalter::Show() { pTxEin->Show(); pTxAus->Show(); pTxZust->Show(); }TextBox.cpp
#include "TextBox.h" #include <string> #include "Winadapt.h" int TextBox::GetX() const { return nX; } int TextBox::GetY() const { return nY; } int TextBox::GetW() const { return nW; } int TextBox::GetH() const { return nH; } const char *TextBox::GetText() const { return szText; } void TextBox::SetX(int X) { TextBox::nX = X; } void TextBox::SetY(int Y) { nY =Y; } void TextBox::SetW(int W) { nW = W; } void TextBox::SetH(int H) { nH = H; } void TextBox::SetText(char *Text) { szText = new char[strlen(Text) + 1]; strcpy(szText, Text); } TextBox::TextBox(char *Text, int X, int Y, int W, int H) { szText = new char[strlen(Text) + 1]; strcpy(szText, Text); nX = X; nY = Y; nW = W; nH = H; } TextBox::TextBox(const TextBox &t) { SetText(t.szText); SetX(t.nX); SetY(t.nY); SetW(t.nW); SetH(t.nH); } TextBox::~TextBox() { delete[] szText; } void TextBox::Show() { Rect(nX,nY,(nX+nW),(nY+nH)); Text(nX+10, nY+8, szText); } int TextBox::Contains(int nX, int nY) { if(nX >= TextBox::nX && nX <= TextBox::nX + TextBox::nW && nY >= TextBox::nY && nY <= TextBox::nY + TextBox::nH) {return 1;} }Winadapt.cpp
#include <stdlib.h> #include <stdio.h> #include <string.h> #include "WinAdapt.h" #include "TextBox.h" #include "Schalter.h" //TextBox t(" Test " ,100 ,100 ,60 ,30); Schalter s("On","Off" ,100 ,100); void VtlZyk(void) { } void VtlMouse(int X, int Y) { } void VtlKeyHit(int key) { } void VtlInit(void) { } void VtlPaint(int xl, int yo, int xr, int yu) { //t. Show (); // 2. Test Show () / Konstruktor //TextBox tt(t); // 3. Test Copykonstruktor //tt. Show (); }winadapt.cpp
/* Windows- Adapter- Programm PIN3 SS99 Kn/Bö DIESE DATEI SOLL NICHT GEAENDERT WERDEN */ #include <windows.h> #include <string.h> #include "WinAdapt.h" #define SIMPROTIMER 4711 #define UPDINTERVALL 200 //msec. zwischen updates HDC Ghdc; extern void VtlPaint(int, int, int, int); extern void VtlZyk(void); extern void VtlMouse(int X, int Y); extern void VtlKeyHit(int key); extern void VtlInit(void); LRESULT CALLBACK WndProc (HWND, UINT, UINT, LONG) ; void Loop(); HPEN hpNewPen=0; HBRUSH hbNewBrush=0; int CALLBACK WinMain( IN HINSTANCE hInstance, IN HINSTANCE hPrevInstance, IN LPSTR lpCmdLine, IN int nShowCmd ) { static char szAppName[] = "HelloWin" ; HWND hwnd ; MSG msg ; WNDCLASS wndclass ; if (!hPrevInstance) { wndclass.style = CS_HREDRAW | CS_VREDRAW ; wndclass.lpfnWndProc = WndProc ; wndclass.cbClsExtra = 0 ; wndclass.cbWndExtra = 0 ; wndclass.hInstance = (HINSTANCE)hInstance ; wndclass.hIcon = LoadIcon(NULL,IDI_APPLICATION); wndclass.hCursor = LoadCursor(NULL,IDC_ARROW); wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wndclass.lpszMenuName = NULL ; wndclass.lpszClassName = szAppName ; RegisterClass (&wndclass) ; } hwnd = CreateWindow (szAppName, //Fenst.klassenname "Anwendungsfenster", //Titelleiste WS_OVERLAPPEDWINDOW, //Fensterstil CW_USEDEFAULT, //Fensterpos, x CW_USEDEFAULT, //Fensterpos, y CW_USEDEFAULT, //horizontale Groesse CW_USEDEFAULT, //vertikale Groesse NULL, //Parent Window NULL, //Handle Menue (HINSTANCE)hInstance, //Handle Instanz NULL) ; //Spezialparameter ShowWindow (hwnd, nShowCmd) ; UpdateWindow (hwnd) ; while (GetMessage (&msg, NULL, 0, 0)) { TranslateMessage (&msg) ; DispatchMessage (&msg) ; } return msg.wParam ; } LRESULT CALLBACK WndProc (HWND hwnd, UINT message, UINT wParam, LONG lParam) { PAINTSTRUCT ps; RECT rect; switch (message) { case WM_CREATE : VtlInit(); SetTimer(hwnd, SIMPROTIMER, UPDINTERVALL, NULL); return 0; case WM_TIMER : if (wParam == SIMPROTIMER){ VtlZyk(); InvalidateRect(hwnd, NULL, TRUE); } return 0; case WM_PAINT : Ghdc = BeginPaint (hwnd, &ps) ; GetClientRect (hwnd, &rect) ; VtlPaint(rect.left, rect.top, rect.right, rect.bottom); EndPaint (hwnd, &ps) ; return 0 ; case WM_LBUTTONUP : VtlMouse(LOWORD(lParam), HIWORD(lParam)); return 0; case WM_CHAR : VtlKeyHit(wParam); return 0; case WM_DESTROY : PostQuitMessage (0) ; return 0 ; } return DefWindowProc (hwnd, message, wParam, lParam) ; } void Text(int xa, int ya, char txt[]) { TextOut(Ghdc, xa, ya, txt, strlen(txt)); } void Line(int xa, int ya, int xe, int ye) { MoveToEx(Ghdc, xa, ya, NULL); LineTo(Ghdc, xe, ye); } void Rect(int xa, int ya, int xe, int ye) { Rectangle(Ghdc, xa, ya, xe, ye); } void Elli(int xa, int ya, int xe, int ye) { Ellipse(Ghdc, xa, ya, xe, ye); } void LineCol(int r, int g, int b) { HPEN hp=hpNewPen; hpNewPen=CreatePen(PS_SOLID, 1, RGB(r,g,b)); SelectObject(Ghdc, hpNewPen); if (hp)DeleteObject(hp); } void FillCol(int r, int g, int b) { HBRUSH hb=hbNewBrush; hbNewBrush=CreateSolidBrush(RGB(r,g,b)); //hbNewBrush=CreateHatchBrush(HS_BDIAGONAL, RGB(r,g,b)); SelectObject(Ghdc, hbNewBrush); if (hb)DeleteObject(hb); } void PutPixel(int xa, int ya, COLORREF crColora) { SetPixel(Ghdc, xa, ya, crColora); } void FillPoly(int* lpPoint, int nPoints) { int fResult=Polygon(Ghdc, (LPPOINT)lpPoint, nPoints); }
-
Scheiße Falscher Bereich. Sorry. Bitte verschieben
-
Dieser Thread wurde von Moderator/in Jochen Kalmbach aus dem Forum C++/CLI mit .NET in das Forum C++ verschoben.
Im Zweifelsfall bitte auch folgende Hinweise beachten:
C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?Dieses Posting wurde automatisch erzeugt.
-
ruebe schrieb:
Hallo, ich vermute das ich einen Fehler im Konstruktor für Schalter habe. Leider finde ich ihn nicht mit der Fehlerausgabe kann ich leider nichts anfangen da mir der Compiler nur "Debug Assertion failed" sagt.
Das heißt aber nicht, dass du uns vorenthalten solltest, wo dieses fehlschlagende assert steht und, falls es in irgendwelchen Teilen der Standardbibliothek passiert, welche deiner Funktionen der unmittelbare Aufrufer ist (Stacktrace). Im Übrigen passen die news nicht zu delete[] und deine Klassen sollten auch einen eigenen Zuweisungsoperator anbieten.
-
ruebe schrieb:
...mit der Fehlerausgabe kann ich leider nichts anfangen da mir der Compiler nur "Debug Assertion failed" sagt. Vllt. sieht ihn einer von euch....
Indem Du uns 450 Zeilen Quellcode vor die Füße wirfst ?
Sorry - soviel unnütze Zeit habe ich nicht übrig.Gruß,
Simon2.
-
Sorry ich wollte eigentlich gestern noch die gesamte Fehlerausgabe einstellen.
Aber durch das Wetter gestern hatte ich keine Internetverbindung.
Hier die gesamte Fehlerausgabe:Debug Assertion Failed!
Programm:... tein\VisualStudio\Projexts\Debug\Schalter.exe
File: f:\dd\vctools\crt_bld\self_x86\crt\src\dbgel.cpp
LINE: 52Expression: _BLOCK_TYPE_IS_VALID(pHead->nBlockUse)
For information see the Visual C++ documentation on asserts.