Jump to content

  • Log In with Google      Sign In   
  • Create Account


Zimans

Member Since 19 May 2000
Offline Last Active Aug 15 2014 06:56 AM

Topics I've Started

Nested template declarations

08 March 2011 - 10:17 AM

I've been looking at the std::shared_ptr and boost::shared_ptr implementations recently trying to learn more advanced template programming and I've encountered a construct that I don't understand, and don't know what it is called to effectively search for it either. For example, here is a simplified snippet from std::shared_ptr

template< class _Ty >
class shared_ptr
{
public:
	template< class _Ux, class _Dx >
	shared_ptr( _Ux *p, _Dx dt );
};

When I create a shared pointer I can specify a deletor, for example:
std::shared_ptr< char > p( malloc( 100 ), free );

The only template type I provide is that of the underlying pointer, in this case char, however the constructor has a template associated with it that seems to get inferred instead of implicitly being defined like the template for the whole class.

At a minimum what is this construct called so I can at least better search for it. Searching for nested templates predominately gives me results on polymorphism with templates.

Can anyone explain to me how the secondary types _Ux and _Dx are inferred?

Thanks,
--Z

Critique my buzzwordDesign Pattern/buzzword please

11 April 2006 - 08:19 AM

Forgive me if this is an established design pattern, as I don't read books like that. What i've started doing recently in place of singletons is the following. I declare a class with all static access members and a single forward declared pointer to the actual implementation of the class. An interface class defenition would look like this:
class Input
{
public:
static void Function1 (void);
static void Function2 (void);

static int Init (void);
static void Release (void);
private:
Input (void);
~Input(void);

static class InputCore *Core;
};
The implementation class will have all the same public members of the interface class and all of it's private whatever. Input will create an instance of the implementation on call of Init. The code for Function1 and Function2 just calls the corresponding function in the implementation. Now I can access the input system via Input::Function1 (); by including input.h, I don't end up including excessive headers, and Input acts as a singleton. An upside is that Init can create different input subsystems based on a passed parameter if I desired by inheriting from a base class. Still the same singleton interface. I don't need a factory either to hold pointer to singletons. My other idea was to replace the static class with a namespace and do the same basic thing. It would work the same, just be wrapped in a namespace and not a class. I know the usual mantra is 'if it works for you use it', and I do, i'm just looking for some outside opinion about possible pitfalls, etc. from the more experienced c++ programmers out there. Thx, --Nate

Singletons, Class Factories, and cyclic dependencies

21 July 2005 - 01:42 PM

Ok, I'm a much better C programmer than C++, but i'm trying. As is everyone else i'm working on my game engine. My quandry is getting pointers to objects that need em the 'right' way. I've started by passing pointers thru functions, but that is sarting to get rediculous. For instance I have a class CConsoleLog (C is for Core class, not class :P ). Just about every class needs to see this as that is my logging mechanism. Not only that it would have to basically be passed into every function. I contemplated letting a class hold on to a pointer to the class, but that seems like a bad idea. Not only do I have to pass Logging, but File System to resource classes, as well as the display for DirectX stuff, etc. An option would be to create a container class that holds on to the pointers for all these core classes, but i still end up passing a class pointer EVERYWHERE. This is just screaming to be a gloabl, but everyone in the C++ world seems to chant "Globals are evil". As I dig around the singleton is another approach to this problem. But even that seems to have two camps for and against. If I was doing this in good'ol C all of my classes would essentially be source files with their associated file local variables and functions. Only the needed functions would be visible outside file scope and anything could use them from anywheres provided the proper header is included. I've also had some cyclic problems. To solve that i've been breaking classes into seperate classes. Again the Logging/Console comes to mind. Just about every object needs to write to the log, but the console also needs to access certain core classes (for input, and rendering). I've split these up, but I still have the problem of getting the pointer. If the log class creates the cmd input class, it still has to get a poointer down to it somehow so it can get input. To help alleviate that I was thinking of using callbacks. But that brings into the mix holding onto a pointer, wich I'm trying to avoid. The answer to it all is probably to do whatever the hell works, but I'm trying to do it proper (And improve my C++). --Zims Tangled in a web of class dependencies

VS.NET 2003 annoyance

05 July 2005 - 06:52 AM

Is there any way to get VS.NET to remember what windows in the workspace are minimized and restore them to minimized when the workspace is loaded? In VS6 if a window was minimized it stayed minimized on load. Now in VS.NET it opens all of them in the workspace. I have two monitors that I stretch my VS workspace over. Whenever I open a file the default window size makes it huge (spanning both monitors). So I open everything, size it accordingly, and then leave it minimized as to preserve the window size. Now whenever I open my project workspace I have to minimize everything. So far I have yet to find an option in the config. Did they forget this attribute while writing VS.NET? --Nate

Q about how AngelScript works

18 June 2005 - 03:01 PM

To start angel script you create an engine, then load scripts into modules (or a single module) Then when you wish to execute a script function you create a context to execute the function in. Here is my question. Does this context have it's own set of global variables and functions, or is this context just used to contain the calling of the function. Globals are still common to all. From what i've read it seems the latter. What i'm after is a way to have per entity data contained in the script. I'm new to scripting so excuse my ignorance. --Zims

PARTNERS