[QUOTE=ZeekyHBomb;26267797]Base<Child> is instanced before Child. As such, Child::Type does not yet exist when Base<Child> is created.
[editline]24th November 2010[/editline]
Well, instanced is the wrong word, but you know what I mean.
At the point where Base<Child> is created, Child only exists as a forward declaration.[/QUOTE]
Ah, makes sense. I guess I have to solve it with composition instead.
If you're using an enum to keep track of the type of an object in a hierarchy you are probably doing something wrong anyway. And should rethink your design so the base does not know about its children, and make sure you don't violate LSP as well. Otherwise use composition whenever possible.
Ok thanks, it apparently reads the minecraft protocol fine so it must work. I don't even want to start trying to make it support longs though.. not using that method anyway.
Also what's the difference between minecraft protocol 4 & 5?
[QUOTE=r4nk_;26268366]If you're using an enum to keep track of the type of an object in a hierarchy you are probably doing something wrong anyway. And should rethink your design so the base does not know about its children, and make sure you don't violate LSP as well. Otherwise use composition whenever possible.[/QUOTE]
The name Type was just a name for the example. The enum I actually use is to keep track of the state. I want the base class to store the state, but I want each child class to have it's own set of states.
[cpp]template<typename T>
class Base
{
public:
enum State;
};
class Child : public Base<Child>
{
};
enum Base<Child>::State
{
TEST
};[/cpp]
Though yeah, like r4nk_ said the parent class should normally not require knowledge of its child-class.
[QUOTE=ZeekyHBomb;26268635][cpp]template<typename T>
class Base
{
public:
enum State;
};
class Child : public Base<Child>
{
};
enum Base<Child>::State
{
TEST
};[/cpp]
Though yeah, like r4nk_ said the parent class should normally not require knowledge of its child-class.[/QUOTE]
That's pretty handy, I didn't know you could do that.
not sure that's a good solution though, as every base becomes a base<type> and you can't hold a pointer to the base, unless you add another parent, which I think defeats the purpose of this whole thing and adds even more classes to the hierarchy. So basically that code would just be using public inheritance for code reuse alone which as we know is a bad idea.
[QUOTE=r4nk_;26268766]That's pretty handy, I didn't know you could do that.
not sure that's a good solution though, as every base becomes a base<type> and you can't hold a pointer to the base, unless you add another parent, which I think defeats the purpose of this whole thing and adds even more classes to the hierarchy. So basically that code would just be using public inheritance for code reuse alone which as we know is a bad idea.[/QUOTE]
Actually, for enums this is just possible since C++0x with the restriction of either making it a strict enum or specifying it's underlying type. Forgot about that :v:
I think Z_guy is aware of that, since this was already the case in his original approach.
I would even disallow casting via protected or private inheritance.
How the hell do you use zlib.net?
I'm a beginner in C# and I need some help 'cause I have some homework for tomorrow's lesson :v:
How do I create a 'for' loop that outputs every number that can be divided by 3 from 3 to 30?
I know basic loops but that's just a bit more complicated, I don't know how to make such restrictions, I already got help with making a loop that shows all of the uneven numbers from 1 to 50 but it was with 'if' and I really don't know anything about that...
[code]
for( int i = 0; i<=30; i++)
{
if((i%3) ==0)
Console.WriteLine (i);
}
[/code]
outputs: 0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30
The key to this is % which gives you the remaining of x/y so if that remaining is 0 then its dividable by that number
Thanks!
% is known as the Modulo operator.
This test.json file has "bad syntax". Can someone help?
{
"encoding" : "UTF-8"
}
[QUOTE=WTF Nuke;26275056]This test.json file has "bad syntax". Can someone help?
{
"encoding" : "UTF-8"
}[/QUOTE]
What's telling you that that's "bad syntax"?
[QUOTE=-HP-;26275136]What's telling you that that's "bad syntax"?[/QUOTE]
Value, object, or array expected on line 1 column 1. Using JSONCPP after a long time of struggling.
[QUOTE=WTF Nuke;26275056]This test.json file has "bad syntax". Can someone help?
{
"encoding" : "UTF-8"
}[/QUOTE]
[url]http://www.jsonlint.com/[/url]
[code]Valid JSON[/code]
Well this is the code [code] Json::Value root; // will contains the root value after parsing.
Json::Reader reader;
bool parsingSuccessful = reader.parse( "test.json", root, false );
if ( !parsingSuccessful )
{
// report to the user the failure and their locations in the document.
std::cout << "Failed to parse configuration\n"
<< reader.getFormatedErrorMessages()
<< "\n";
}[/code]
[QUOTE=Richy19;26272513][code]
for( int i = 0; i<=30; i++)
{
if((i%3) ==0)
Console.WriteLine (i);
}
[/code]
outputs: 0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30
The key to this is % which gives you the remaining of x/y so if that remaining is 0 then its dividable by that number[/QUOTE]
This irks me because technically all you need to do is increment by 3 each time. You know you'll hit every number divisible by three by just adding three to the previous one. Sadly though, if it's for homework, the teacher probably wants modulo used and can't think of a better example where it actually makes sense to use.
[QUOTE=ZeekyHBomb;26269111]
I would even disallow casting via protected or private inheritance.[/QUOTE]
Using private inheritance in cases like this is called the "class mixin pattern", often used with multiple inheritance. Just thought I'd put that up here.
(Also, don't use protected inheritance for this. It's nonsense.)
[QUOTE=WTF Nuke;26275396]Well this is the code [code] Json::Value root; // will contains the root value after parsing.
Json::Reader reader;
bool parsingSuccessful = reader.parse( "test.json", root, false );
if ( !parsingSuccessful )
{
// report to the user the failure and their locations in the document.
std::cout << "Failed to parse configuration\n"
<< reader.getFormatedErrorMessages()
<< "\n";
}[/code][/QUOTE]
I believe you are using it wrong. The parser is probably trying to parse "test.json" instead of the actual json. [url=http://jsoncpp.sourceforge.net/class_json_1_1_reader.html#f1da6c976ad1e96c742804c3853eef94]Look here.[/url]
The Lua for Windows classlib and LOVE continue to infuriate me. When used together, only half of classlib's features work :argh:
I can't access what class an object is or even inherit classes! D:
[QUOTE=thejjokerr;26285089]Is there a way to get directly into the memory of your graphics cards, as in, getting the address of each pixel on your screen, or at least where it starts?[/QUOTE]
Sure, 0xB8000 for text mode, 0xA8000 for VGA mode.
Oh you mean from userland? Of course not
I've always wondered how the BIOS and such draw both graphics and text on the screen.
Do they go to VGA mode first?
[code]
/****************************************************************
* example1
* this application shows how to setup a standard windows
* application
* No DirectX libraries are needed to compile this.
****************************************************************/
#include <windows.h>
#include <tchar.h>
// Globals //////////////////////////////////////////////////////
HINSTANCE hInst;
HWND mainhWnd;
int width = 640;
int height = 480;
// Forward declarations //////////////////////////////////////////
bool InitWindow(HINSTANCE hInstance, int width, int height);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
/*******************************************************************
* WinMain
*******************************************************************/
int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
// Set up the application window
if (!InitWindow(hInstance, width, height))
{
return false;
}
// Main message loop
MSG msg = {0};
while (WM_QUIT != msg.message)
{
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) == TRUE)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return (int) msg.wParam;
}
/*******************************************************************
* InitWindow
* Inits and creates and main app window
* Inputs - application instance - HINSTANCE
Window width - int
Window height - int
* Outputs - true if successful, false if failed - bool
*******************************************************************/
bool InitWindow(HINSTANCE hInstance, int width, int height)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = 0;
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = TEXT("DirectXExample")
wcex.hIconSm = 0;
RegisterClassEx(&wcex);
// Resize the window
RECT rect = { 0, 0, width, height };
AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, FALSE);
// create the window from the class above
mainhWnd = CreateWindow(TEXT("Benchmarker"),
TEXT("Benchmarker"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
rect.right - rect.left,
rect.bottom - rect.top,
NULL,
NULL,
hInstance,
NULL);
if (!mainhWnd)
{
return false;
}
ShowWindow(mainhWnd, SW_SHOW);
UpdateWindow(mainhWnd);
return true;
}
/*******************************************************************
* WndProc
* The main window procedure for the application
* Inputs - application window handle - HWND
message sent to the window - UINT
wParam of the message being sent - WPARAM
lParam of the message being sent - LPARAM
* Outputs - LRESULT
*******************************************************************/
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
// Allow the user to press the escape key to end the application
case WM_KEYDOWN:
switch(wParam)
{
// Check if the user hit the escape key
case VK_ESCAPE:
PostQuitMessage(0);
break;
}
break;
// The user hit the close button, close the application
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return DefWindowProc(hWnd, message, wParam, lParam);
}
[/code]
Error:
Error 1 error C2146: syntax error : missing ';' before identifier 'wcex' c:\users\linuxfp\documents\visual studio 2005\projects\directx\directx\winmain.cpp 68
It's my first time using it, I know.
The error message is pretty clear, you missed a semicolon on line 67.
[cpp]wcex.lpszClassName = TEXT("DirectXExample")[/cpp]
It means exactly what it says, missing semicolon.
[code]wcex.lpszMenuName = NULL;
wcex.lpszClassName = TEXT("DirectXExample")
wcex.hIconSm = 0;
RegisterClassEx(&wcex);[/code]
Spot the missing semicolon.
Unless that TEXT macro doesn't need a semicolon, not sure what it does.
Line 67 you forgot a ";"
Ninja'd by two people..
[QUOTE=r4nk_;26286190]It means exactly what it says, missing semicolon.
[code]wcex.lpszMenuName = NULL;
wcex.lpszClassName = TEXT("DirectXExample")
wcex.hIconSm = 0;
RegisterClassEx(&wcex);[/code]
Spot the missing semicolon.
Unless that TEXT macro doesn't need a semicolon, not sure what it does.[/QUOTE]
I don't see it.
wcex.lpszClassName = TEXT("DirectXExample");
Gives me a 0x0
What is a 0x0
[QUOTE=r4nk_;26286280]What is a 0x0[/QUOTE]
The program '[6792] DirectX.exe: Native' has exited with code 0 (0x0).
Sorry, you need to Log In to post a reply to this thread.