Ahoj, co napsat do hlavičkových souborů, aby bylo jasný, že je to ode mě. Co by uživatelům říkalo, aby s mojí prácí zacházeli s trochou slušnosti a uváděli moje jméno jako autora, kdyby to chtěli dál šířit nebo upravovat?
Příspěvky odeslané z IP adresy 88.100.108.–
ten soubor se dá normálně číst hexeditorem, ale normálně, když to třeba otevřu v klasickým textovým editoru, je to změť znaků, které vypadájí jako z .exe souborů. Je tam spousta proměných a myslím, že nebude těžké zjisti co budou zač. Poradíte nějakou knihovnu, která by s tím byla schopna pracovat?
Díky. Snad mám ty nejzávažnější chyby opraveny. Některých věcí jsem si nevšiml. Pokud se vám zdál jeden z předchozích příspěvků nejasných, tak s šablonama teprve začínám a ani jsem nevěděl, jak ten problém pojmenovat. Až budu mít zase čas budu pokračovat. :-)
#pragma once
#include <stdio.h>
#include <stdlib.h>
//namespace Neuron_Class {
template <class Data, class Synapse>
class VECTOROFNEURON
{
public:
VECTOROFNEURON ();
~VECTOROFNEURON ();
bool GetNext ();
bool IsSynapse (Synapse *);
int GetIncrease (int);
Synapse *GetSynapse ();
VECTOROFNEURON<Data,Synapse> *GetTo (int num,int i);
VECTOROFNEURON<Data,Synapse> *GetTo (Synapse *);
VECTOROFNEURON<Data,Synapse> *GetLast ();
VECTOROFNEURON<Data,Synapse> *GetThis ();
VECTOROFNEURON<Data,Synapse> *ConstructNext ();
void SetSynapse (Synapse *);
private:
Synapse *synapse;
Data *data;
VECTOROFNEURON<Data,Synapse> *next;
};
class INPUTOFNEURON
{
public:
INPUTOFNEURON ();
~INPUTOFNEURON ();
private:
int *input;
float *w;
};
class OUTPUTOFNEURON
{
public:
OUTPUTOFNEURON ();
~OUTPUTOFNEURON ();
private:
};
class NEURON
{
public:
NEURON ();
~NEURON ();
bool ConstructNewSynapse(NEURON *);
bool IsSynapse (NEURON *);
bool SetSynapse(NEURON *, int);
int GetCountInput ();
VECTOROFNEURON<INPUTOFNEURON, NEURON> *ConstructInput ();
VECTOROFNEURON<INPUTOFNEURON, NEURON> *GetFirstInput ();
VECTOROFNEURON<INPUTOFNEURON, NEURON> *GetInput (int);
VECTOROFNEURON<INPUTOFNEURON, NEURON> *GetInput (NEURON *);
VECTOROFNEURON<INPUTOFNEURON, NEURON> *GetLastInput ();
/* void ConstructOutput ();*/
private:
int *output;
float *p;
VECTOROFNEURON<INPUTOFNEURON, NEURON> *thisInput;
VECTOROFNEURON<OUTPUTOFNEURON, NEURON> *thisOutput;
};
NEURON::NEURON ()
{
output = new int;
p = new float;
*output = 0;
*p = 0;
};
NEURON::~NEURON ()
{
delete output;
delete p;
};
bool NEURON::ConstructNewSynapse(NEURON * rightSide)
{
VECTOROFNEURON<INPUTOFNEURON, NEURON> * i;
i = this->GetInput (rightSide);
if (i->GetSynapse ())
{
return false;
}
else
{
VECTOROFNEURON<INPUTOFNEURON, NEURON> *j;
j = this->ConstructInput ();
j->SetSynapse (j->GetSynapse ());
return true;
}
};
bool NEURON::IsSynapse (NEURON * rightSide)
{
if (this->GetFirstInput ())
{
if(rightSide == thisInput->GetSynapse ())
{
return true;
}
else
{
return this->IsSynapse (rightSide);
}
}
else
{
return false;
}
};
bool NEURON::SetSynapse(NEURON * rightSide, int i)
{
VECTOROFNEURON<INPUTOFNEURON, NEURON> *j;
j = this->GetInput (i);
if (j)
{
j->SetSynapse (rightSide);
return true;
}
else
{
return false;
}
};
int NEURON::GetCountInput ()
{
int i = 0;
if (this->GetFirstInput ())
{
return thisInput->GetIncrease (i);
}
return i;
};
VECTOROFNEURON<INPUTOFNEURON, NEURON> *NEURON::GetFirstInput ()
{
if (thisInput)
return this->thisInput;
else
return 0;
};
VECTOROFNEURON<INPUTOFNEURON, NEURON> *NEURON::GetInput (int num)
{
int i = 0;
if (this->GetFirstInput ())
{
if (num == i)
{
return this->thisInput;
}
else
{
++i;
return thisInput->GetTo (num, i);
}
}
else
{
return 0;
}
};
VECTOROFNEURON<INPUTOFNEURON, NEURON> *NEURON::GetInput (NEURON *rightSide)
{
if (this->GetFirstInput ())
{
if (rightSide == thisInput->GetSynapse ())
{
return this->thisInput;
}
else
{
return thisInput->GetTo (rightSide);
}
}
else
{
return 0;
}
};
VECTOROFNEURON<INPUTOFNEURON, NEURON> *NEURON::GetLastInput ()
{
if (this->GetFirstInput ())
return thisInput->GetLast ();
else
return 0;
};
VECTOROFNEURON<INPUTOFNEURON, NEURON> *NEURON::ConstructInput ()
{
if (this->GetFirstInput ())
{
return thisInput->ConstructNext ();
}
else
{
thisInput = new VECTOROFNEURON<INPUTOFNEURON, NEURON>;
return thisInput;
}
};
template <class Data, class Synapse>
VECTOROFNEURON<Data, Synapse>::VECTOROFNEURON ()
{
data = new Data;
};
template <class Data, class Synapse>
VECTOROFNEURON<Data, Synapse>::~VECTOROFNEURON ()
{
delete data;
};
template <class Data, class Synapse>
bool VECTOROFNEURON<Data,Synapse>::GetNext ()
{
if (next)
return true;
else
return false;
};
template <class Data, class Synapse>
bool VECTOROFNEURON<Data,Synapse>::IsSynapse (Synapse *rightSide)
{
if (this->GetFirstInput ())
{
if(rightSide == thisInput->GetSynapse ())
{
return true;
}
else
{
return next->IsSynapse (rightSide);
}
}
else
{
return false;
}
};
template <class Data, class Synapse>
int VECTOROFNEURON<Data,Synapse>::GetIncrease (int i)
{
if (this->GetNext ())
{
++i;
return next->GetIncrease (i);
}
return i;
};
template <class Data, class Synapse>
Synapse *VECTOROFNEURON<Data,Synapse>::GetSynapse ()
{
return this->synapse;
};
template <class Data, class Synapse>
VECTOROFNEURON<Data,Synapse> *VECTOROFNEURON<Data,Synapse>::ConstructNext ()
{
if (this->GetNext ())
{
return next->ConstructNext ();
}
else
{
next = new VECTOROFNEURON<INPUTOFNEURON, NEURON>;
return next;
}
};
template <class Data, class Synapse>
VECTOROFNEURON<Data,Synapse> *VECTOROFNEURON<Data,Synapse>::GetTo(int num, int i)
{
if (next->GetNext ())
{
if (num == i)
{
return next;
}
else
{
++i;
return this->GetTo (num, i);
}
return this;
}
else
{
return 0;
}
};
template <class Data, class Synapse>
VECTOROFNEURON<Data,Synapse> *VECTOROFNEURON<Data,Synapse>::GetTo (Synapse *rightSide)
{
if (rightSide)
{
return this;
}
else
{
if (this->GetNext ())
{
return next->GetTo (rightSide);
}
else
{
return 0;
}
}
};
template <class Data, class Synapse>
VECTOROFNEURON<Data,Synapse> *VECTOROFNEURON<Data,Synapse>::GetLast ()
{
if (this->GetNext ())
{
return next->GetLast ();
}
else
{
return this;
}
};
template <class Data, class Synapse>
VECTOROFNEURON<Data,Synapse> *VECTOROFNEURON<Data,Synapse>::GetThis ()
{
return this;
};
template <class Data, class Synapse>
void VECTOROFNEURON<Data,Synapse>::SetSynapse (Synapse * rightSide)
{
synapse = rightSide;
};
INPUTOFNEURON::INPUTOFNEURON ()
{
input = new int;
w = new float;
*input = 0;
*w = rand() % 100 + 0;
*w = *w/100;
};
INPUTOFNEURON::~INPUTOFNEURON ()
{
delete input;
delete w;
};
//};
1>------ Rebuild All started: Project: Neural_Network, Configuration: Debug Win32 ------
1> stdafx.cpp
1>c:\users\verewolf2\desktop\neural_network\neural_network\Neuron.h(206): error C2065: 'rightSide' : undeclared identifier
1>c:\users\verewolf2\desktop\neural_network\neural_network\Neuron.h(206): error C2597: illegal reference to non-static member 'VECTOROFNEURON<Data,NEURON>::NEURON'
1>c:\users\verewolf2\desktop\neural_network\neural_network\Neuron.h(206): error C3867: 'VECTOROFNEURON<Data,NEURON>::NEURON': function call missing argument list; use '&VECTOROFNEURON<Data,NEURON>::NEURON' to create a pointer to member
1>c:\users\verewolf2\desktop\neural_network\neural_network\Neuron.h(206): warning C4346: 'VECTOROFNEURON<Data,NEURON>::GetNext' : dependent name is not a type
1> prefix with 'typename' to indicate a type
1>c:\users\verewolf2\desktop\neural_network\neural_network\Neuron.h(206): error C2350: 'VECTOROFNEURON<Data,NEURON>::GetNext' is not a static member
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
Tak jsem se pokusil udělat API program, kde jsem chtěl vytvořit pole tlačítek, ale neuvědomil jsem si, že paměť bez příkazu new, delete je velmi omezená (jak že se týhletý paměti říká?, nějak si nemůžu vzpomenout, nemám s kým se o tom bavit.) Docela jsem čuměl, když jsem to zjistil.
Asi bude nejlepší si vytvořit vlastní šablonu třídy pole, která by uměla pracovat s dynamickou pamětí... :-D To jsou ty začátky. :-)
/* THIS FILE WILL BE OVERWRITTEN BY DEV-C++ */
/* DO NOT EDIT ! */
#ifndef VEREAPP_PRIVATE_H
#define VEREAPP_PRIVATE_H
/* VERSION DEFINITIONS */
#define VER_STRING "0.1.1.1"
#define VER_MAJOR 0
#define VER_MINOR 1
#define VER_RELEASE 1
#define VER_BUILD 1
#define COMPANY_NAME ""
#define FILE_VERSION ""
#define FILE_DESCRIPTION "Developed using the Dev-C++ IDE"
#define INTERNAL_NAME ""
#define LEGAL_COPYRIGHT ""
#define LEGAL_TRADEMARKS ""
#define ORIGINAL_FILENAME ""
#define PRODUCT_NAME ""
#define PRODUCT_VERSION ""
#define IDI_ICON 101
#define IDI_HICON 102
#define IDI_HICONSM 103
#define IDT_TIMER 201
#define IDM_NEW 40001
#define IDM_SCORE 40002
#define IDM_END 40003
#define IDM_RULES 40004
#define IDM_ABOUT 40005
#endif /*VEREAPP_PRIVATE_H*/
Ahoj,
zkouším vytvořit checkmenu, ale nějak mi to nejde. Políčko stále zůstává zaškrtnuté, ikdyž na něj znovu kliknu.
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include "VereApp_private.h"
/* Declare Windows procedure */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
/* Make the class name into a global variable */
char szClassName[ ] = "WindowsApp";
int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)
{
HWND hwnd; /* This is the handle for our window */
MSG messages; /* Here messages to the application are saved */
WNDCLASSEX wincl; /* Data structure for the windowclass */
/* The Window structure */
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */
wincl.style = CS_DBLCLKS; /* Catch double-clicks */
wincl.cbSize = sizeof (WNDCLASSEX);
/* Use default icon and mouse-pointer */
wincl.hIcon = LoadIcon (hThisInstance, MAKEINTRESOURCE("IDI_HICON"));
wincl.hIconSm = LoadIcon (hThisInstance, MAKEINTRESOURCE("IDI_HICONSM"));
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = "MAINMENU"; /* No menu */
wincl.cbClsExtra = 0; /* No extra bytes after the window class */
wincl.cbWndExtra = 0; /* structure or the window instance */
/* Use Windows's default color as the background of the window */
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
/* Register the window class, and if it fails quit the program */
if (!RegisterClassEx (&wincl))
return 0;
/* The class is registered, let's create the program*/
hwnd = CreateWindowEx (
0, /* Extended possibilites for variation */
szClassName, /* Classname */
"Vere App", /* Title Text */
WS_OVERLAPPEDWINDOW, /* default window */
CW_USEDEFAULT, /* Windows decides the position */
CW_USEDEFAULT, /* where the window ends up on the screen */
544, /* The programs width */
375, /* and height in pixels */
HWND_DESKTOP, /* The window is a child-window to desktop */
NULL, /* No menu */
hThisInstance, /* Program Instance handler */
NULL /* No Window Creation data */
);
/* Make the window visible on the screen */
ShowWindow (hwnd, nFunsterStil);
/* Run the message loop. It will run until GetMessage() returns 0 */
while (GetMessage (&messages, NULL, 0, 0))
{
/* Translate virtual-key messages into character messages */
TranslateMessage(&messages);
/* Send message to WindowProcedure */
DispatchMessage(&messages);
}
/* The program return-value is 0 - The value that PostQuitMessage() gave */
return messages.wParam;
}
/* This function is called by the Windows function DispatchMessage() */
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hDC;
HMENU hMenu;
PAINTSTRUCT ps;
RECT rect;
int posX = 0;
int posY = 0;
UINT checkRules = 0;
char buffer [33];
switch (message) /* handle the messages */
{
case WM_COMMAND:
hMenu = GetMenu(hwnd);
switch (wParam)
{
case IDM_NEW:
SetTimer(hwnd,IDT_TIMER,500,NULL);
break;
case IDM_END:
PostQuitMessage (0);
break;
case IDM_RULES:
switch (checkRules)
{
case 0:
CheckMenuItem(hMenu, IDM_RULES, MF_CHECKED);
checkRules = 1;
break;
default:
CheckMenuItem(hMenu, IDM_RULES, MF_UNCHECKED);
checkRules = 0;
break;
}
break;
}
break;
case WM_PAINT:
break;
case WM_TIMER:
switch (wParam)
{
case IDT_TIMER:
SetWindowPos(hwnd,NULL,++posX,++posY,512,256 ,NULL);
break;
}
break;
case WM_DESTROY:
PostQuitMessage (0); /* send a WM_QUIT to the message queue */
break;
default: /* for messages that we don't deal with */
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}
#include "VereApp_private.h"
#include "afxres.h"
IDI_ICON ICON DISCARDABLE "Resource/Icon.ico"
IDI_HICON ICON DISCARDABLE "Resource/hIcon.ico"
IDI_HICONSM ICON DISCARDABLE "Resource/hIconSM.ico"
MAINMENU MENU DISCARDABLE
BEGIN
POPUP "&Game"
BEGIN
MENUITEM "&New Game", IDM_NEW
MENUITEM "&Score", IDM_SCORE
MENUITEM "&End", IDM_END
END
POPUP "&Help"
BEGIN
MENUITEM "&Rules", IDM_RULES
MENUITEM "&About App", IDM_ABOUT
END
END
Ještě by mě zajímalo, jak nejlépe udělat to dělení. Abych to nemusel dávat do kopírovacího constructoru. Když jsem se vzorec pokusil vložit do funkce GetResultValue (), tak mě to napsalo:
30 C:\Users\VereWolf2\Desktop\Untitled1.cpp:49 assignment of member 'Division::itsResultValue' in read-only object
#include <iostream> using namespace std; class Division { public: Division (); Division (Division&); ~Division (); float GetDownValue () const {return itsDownValue;} float GetResultValue () const; float GetUpValue () const {return itsUpValue;} void SetDownValue (float downValue) {itsDownValue = downValue;} void SetUpValue (float upValue) {itsUpValue = upValue;} class xNullDownValue {}; private: float itsDownValue; float itsResultValue; float itsUpValue; }; Division::Division (): itsDownValue(1), itsResultValue(0), itsUpValue(0) { cout << "Constructor" << endl; } Division::Division (Division& object) { cout << "copy Constructor" << endl; if (object.itsDownValue == 0) { throw xNullDownValue(); } itsDownValue = object.GetDownValue (); itsUpValue = object.GetUpValue (); itsResultValue = itsUpValue / itsDownValue; } Division::~Division () { cout << "Destructor" << endl; } float Division::GetResultValue () const { itsResultValue = itsUpValue / itsDownValu; return itsResultValue; } int main(int argc, char *argv[]) { try { float down,up; Division first; cout << "Napis horni hodnotu: "; cin >> up; cout << endl; first.SetUpValue(up); cout << "Napis dolni hodnotu: "; cin >> down; cout << endl; first.SetDownValue(down); Division two = first; cout << first.GetResultValue () << endl; cout << two.GetResultValue () << endl; } catch (Division::xNullDownValue) { cout << "Down value is Null!" << endl; } catch (...) { cout << "error!" << endl; } cout << "Press the enter key to continue ..."; cin.get(); cin.get(); return 0; }
Zdravím, mám problémy s kopírovacím konstructorem, který se nevolá, když požiju kteroukoliv funkci v třídě. Mám přečtenou knihu Naučte se C++ za 21 dní (2007).Zde je příklad:
#include <iostream>
using namespace std;
class Division
{
public:
Division ();
Division (Division&);
~Division ();
float GetDownValue () const {return itsDownValue;}
float GetResultValue () const {return itsResultValue;}
float GetUpValue () const {return itsUpValue;}
void SetDownValue (float downValue) {itsDownValue = downValue;}
void SetUpValue (float upValue) {itsUpValue = upValue;}
class xNullDownValue {};
private:
float itsDownValue;
float itsResultValue;
float itsUpValue;
};
Division::Division ():
itsDownValue(1),
itsResultValue(0),
itsUpValue(0)
{
cout << "Constructor" << endl;
}
Division::Division (Division&)
{
cout << "copy Constructor" << endl;
if (itsDownValue == 0)
{
throw xNullDownValue();
}
itsResultValue = itsUpValue/itsDownValue;
}
Division::~Division ()
{
cout << "Destructor" << endl;
}
int main(int argc, char *argv[])
{
try
{
Division first;
cout << first.GetResultValue () << endl;
}
catch (Division::xNullDownValue)
{
cout << "Down value is Null!" << endl;
}
catch (...)
{
cout << "error!" << endl;
}
cout << "Press the enter key to continue ...";
cin.get();
return 0;
}