Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

122 Neutral

About Anima

  • Rank
  1. I'm writing a user control in C# which can have other controls placed on it (like a panel). Now I want to be able to define the area in which these controls can be placed - I think this is called the client area, but I could be wrong. A nice example of what I'm trying to achieve can be seen with the TabControl, there is a dotted rectangle which shows where you can place other controls - how can I do something similar with my own control?
  2. *smacks self in face* I should've known that... Thanks, all.
  3. I've been having problems with a program and eventually found the source of the problem which is demonstrated by the following code: #include <list> #include <iostream> class cString { public: cString (){ str = 0; } virtual ~cString () { if (str != 0) delete [] str; } char* str; }; int main () { std::list <cString> List; cString string; string.str = new char [32]; List.push_back (string); return 0; } Running this will cause the program to crash because the deconstructor is called twice, once when the cString object is destroyed and again when the list is destroyed. Although I can see the cause of the problem I've been having a hard time trying to find a solution to it. The following code is from my actual project: { // ... cARC_FileInfo newFile; newFile.SetName (strName); newFile.SetFilePath (strFilePath); newFile.SetLength (0); newFile.SetOffset (0); m_FileTable.push_back (newFile); return true; } As you can see, the code creates a temporary object, sets the properties (including memory allocation in SetName), and then appends this to the m_FileTable list. However, when the function end is reached, the temporary object is destroyed, which destroys the string which the object in the list is still pointing to. What is the best way to avoid this problem?
  4. Anima

    32-bit - long or int?

    Is it advisable to use __int32? I don't know how much of an impact this would have on compiler-compatibility. I've read the replies and the best solution seems to be to use the boost library which I don't mind using, but am trying to stay away from for the sake of making the code easier to distribute. Also, my stdint.h seems to have gone AWOL! This is a really daft question, and I'm pretty sure I know the answer already, but once a program has been compiled in a 32bit environment (where an int is 32 bits), it will remain 32 bits when run in a 64-bit environment, right?
  5. Simple question. Are there any guarantees as to whether a C++ 'long' or 'int' will remain 32 bits long in the future? I need to use one of them but also need to ensure that 'x' years down the line it will still be 32 bits long.
  6. Anima

    Compiling gzstream

    That simple, eh? I should've realised this because I've had a very similar problem before. Well, it works now anyway. Thanks
  7. I've been trying to create a compressed file reader similar to gzstream (http://www.cs.unc.edu/Research/compgeom/gzstream/). The problem is that I've not had a chance to use it because I can't get it to compile. The errors aren't in the source code but in the STL headers, specifically cerrno.h, cstdlib.h, and cstdio.h. The first few errors which occur are: c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\cerrno(16) : error C2143: syntax error : missing '{' before ':' c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\cerrno(16) : error C2059: syntax error : ':' There are 204 errors, so I won't post them all! The above two errors appear in the following part of the cerrno.h header. _STD_BEGIN #ifndef errno using ::errno; // <- Here #endif _STD_END I'm using MSVC++ 7.0, after just ditching 6.0 in hope of ridding myself of STL problems like this. Does anyone have a clue what the problem might be? The code isn't using any of the old '.h' headers (e.g. iostream.h), if this matters.
  8. Anima

    Inheritance Problem

    Well, whilst writing a 'trimmed down' code example of the problem I found out what the problem is - I'd simply forgot to make the derived function 'constant'. The following code shows where I went wrong if anyone is interested: #include <iostream> class cBase { public: virtual int GetMinLevel () const { return 0; }; virtual int GetMaxLevel () const { return 9; }; virtual int Range () { return GetMaxLevel () - GetMinLevel (); }; }; class cDerived : public cBase { int GetMinLevel () { return 0; }; // * int GetMaxLevel () { return 4; }; // * }; int main () { cDerived test; std::cout << test.Range () << endl; return 1; } The program will output 9 rather than 4 because I hadn't made the marked (*) functions constant. It's something else learned, anyway!
  9. Anima

    Inheritance Problem

    It could be this is supposed to happen - or it could be just the compiler (the accursed VC++ 6.0) and one of its many bugs. Has anyone got any idea what the problem could be? Or have I just got the inheritance model messed up?
  10. Anima

    Inheritance Problem

    Yes, both GetMinLevel and GetMaxLevel are defined as virtual in the base class.
  11. I hope someone can help with this, but its kinda difficult for me to explain. I've been messing around with inheritance, but have come across a problem. I have a base class with contains the following function: eCWresult cCompressor::Compress_Init2 (const int iPercentage) { float fRatio = (iPercentage / 100.0f); int iLevel = GetMinLevel () + (int)((GetMaxLevel () - GetMinLevel ()) * fRatio); return Compress_Init (iLevel); } The GetMinLevel and GetMaxLevel function are members of this base class. The problem is that when I derive a new class from this base class and replace the GetMinLevel and GetMaxLevel functions, it is still the original functions that are called when I call the Compress_Init2 function. The only way I've found to make it behave correct is to redefine the Compress_Init2 function in the derived class (even though it still has the same body) Is there a better way? (... I hope I explained that well enough.)
  12. Anima

    Archived Files

    Me again. OK, I've been hammering away at the 'theory' of this for a while, and I'm still quite confused about how I should approach this. Again, as far as I can see, for a basic implementation I have to derive a class from std::streambuf, and then derive another from std::ifstream. Then I have to attach the derived stream buffer class using rdbuf. The derived streambuf class will need the underflow function replacing to handle the compressed data. Am I still on the right lines here? A few relatively minor things that are bothering me (besides actually getting started with this) are the seekg/tellg/eof and maybe some other functions. Do I need to derive new functions of these as well? These will be done later after I've at least got the reading functions working, but I think its worth thinking about in advance. Thanks for all your help so far.
  13. Anima

    Archived Files

    So, from what I gather so far (correct me if I'm wrong) is that I've got to derive a class from streambuf to handle the decompression, and then derive a class from ifstream which will use the derived streambuf? Can someone put me straight on this before I attempt this? (I'm starting to think this is a little over my head - but I'll stick with it for a while) [crying]
  14. Anima

    Archived Files

    Thanks for the replies. An idea I have been toying with to increase compatibility is to derive a file reader class from STL's std::ifstream. This would (potentially) hide all of complications of using these files and allow them to be used in the same way as a normal file. The problem now is that I'm not sure which class to derive from (basic_istream, basic_ifstream, filebuf, streambuf?) - the STL inheritance model is quite complicated is this respect. Is it even necessary to create custom filebuf or streambuf classes? As you can probably tell already I'm going to have to familarise myself with these STL components some more. However, any advice on how I should approach this would be most welcome.
  15. I've been working on a project to create an 'archive' file format (similar to ZIP) in C++. (Before you ask I'm only doing it to help broaden my knowledge of the language - this kind of project tends to do so. ) However, I realised that this and even the ZIP format might be quite impractical to use with external code and libraries. The one that springs immediately to mind is the image library DevIL. I've been trying to work out a way how I can feed the data from a compressed/encrypted file in an archive into the library. The only solution I can think of is to extract the file from the archive and then give that to the library instead. Is this really the best/only way I could go about this?
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!