Advertisement Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

154 Neutral

About Rainault

  • Rank
  1. public delegate T Func<T>(T t); static public TList SomeMethod<TList, T>(Func<T> f, TList list) where TList : IList<T>, new() { // Do stuff } Above is roughly the source of the method of a class I'm working on. It takes in a delegate and a list, does some magic, and spits out another list. Trouble is, it doesn't seem to like it when I try to call the method, like below: List<int> mylist = {/* blah */}; List<int> newlist = SomeMethod(delegate(int i){/* return an int */}, mylist); I get this error message: The type arguments for method 'blah' cannot be inferred from the usage. Try specifying the type arguments explicitly. Looking at the code, it seems pretty clear to me what the type arguments should be: TList is List<T>, and T is int. TList can't be anything else, since I required TList to be derived from IList<T> and constructible. T is obviously an int because of the delegate I provide. What am I missing here? I would strongly prefer not to specify the type arguments, as "SomeMethod<List<int>, int>(...)" is a little too clunky for me. [Edited by - Rainault on May 27, 2008 11:01:42 PM]
  2. I actually come from a predominantly C++ background, though recently I've been doing more ASP.NET/C# development. I haven't done much Windows app development, and the few that I have done used SDKs that wrapped all of the gory details. But I've taken some ideas from what you said. We'll see where I can go with it. Thanks for the help. :)
  3. I need to create a dialog box for my Windows application in Visual Studio 2005. I am using unmanaged C++, and my target platform is Vista. I've created a dialog resource in my project, and I've also written a class derived from CDialog that I want to use for this resource. However, when I right-click on the dialog box, the "Add Class" item is grayed out. I can cause the dialog box to display in my application without an issue. I just want to use my class to define the behavior of the dialog box. How would I do this?
  4. Rainault

    anyone know what wrong

    Oh, also, if "level" is a char variable, then you should be doing level == '1' and not level == 1
  5. Rainault

    anyone know what wrong

    1. Your function is called "difficulty", not "Difficulty". Verify the consistency between naming your functions and calling them. 2. Don't put the "void" in front of the difficulty function call. You only need the return type of a function in its signature. 3. main should have a return type of int and return 0. Those are the three things that stick out the most, aside from the fact that you're missing #includes.
  6. As an example that uses container data structures, linked lists generally do not support random access, while vectors do. A linked list can only access a random element in linear time, so it's generally an inefficient operation when compared to other containers if random access is needed regularly. A vector, however, does support random access in constant time. For example, the SC++L std::vector class uses a contiguous chunk of memory to hold the data, so simple pointer arithmetic makes constant time random access easy. A std::list, however, must go through each node to get to an arbitrary element, since each node only knows about its previous and next nodes. Iterators are generally preferable to indices, since you can let the iterator worry about the access method. All you care about is the value that the iterator returns. Indices presume that random access is supported when it may not be. (e.g. what if you change from using a vector to a linked list?)
  7. Rainault

    Advice on purchasing computer parts

    Okay, so the general consensus is that I should pick a better CPU. I compared some Core 2 Duo models to Athlon X2 models, and I'm having trouble making a good comparison between them. I'm looking at these two which are within the same price range: Intel Core 2 Duo E6400 Conroe 2.13GHz LGA 775 Processor 64 bit Support: Yes FSB: 1066MHz Hyper-Threading Support: No L1 Cache: 32KB+32KB L2 Cache: 2M sharing Virtualization Technology Support: Yes AMD Athlon 64 X2 4400+ Toledo 2.2GHz Socket 939 Dual Core Processor 64 bit Support: Yes HT: 2000MHz Hyper-Transport Support: Yes L1 Cache: 128KB+128KB L2 Cache: 2 x 1MB Virtualization Technology Support: No Obviously, the AMD model has a larger L1 cache, though I'm not sure what the "2M sharing" thing means for the Intel model. Does that mean the processor shares its cache with other things? I also don't know how to compare the FSB with the HyperTransport rates. I looked up the Intel Core 2 Duo 6600 model, and I'm not sure if I want to pay the $100 difference from the 6400 model listed above. Is the increase in performance worth it?
  8. I'm giving my computer a much needed upgrade. I plan on purchasing a new motherboard, processor, RAM, hard drive, and video card. From the specs on the video card I'm looking at, it looks like I need a new power supply, too. So I'm more or less buying a new computer. Anyway, these are the parts I'm looking at. I plan on using this computer for some serious gaming, so I'd like to beef this up now rather than buy mediocre parts and have to upgrade so soon later. Intel BOXDG965SSCK Socket T (LGA 775) Intel G965 Express Micro ATX Intel Motherboard - $106.99 Intel Pentium D 805 Smithfield 2.66GHz LGA 775 Dual Core,EM64T Processor Model BX80551PE2666FN - $99.99 CORSAIR XMS2 2GB (2 x 1GB) 240-Pin DDR2 SDRAM DDR2 800 (PC2 6400) Dual Channel Kit Desktop Memory Model TWIN2X2048-6400 - $279.00 Seagate Barracuda 7200.10 ST3320620AS (Perpendicular Recording Technology) 320GB 7200 RPM SATA 3.0Gb/s Hard Drive - $94.99 Rosewill RP500-2 ATX 2.01 500W Power Supply - $47.99 ATI Radeon X1600 PRO 512MB PCI-Express Graphics Card - $199.99 Technically, I'm not working on a specific budget. However much this costs, I plan on saving up for it. I have about $400-500 saved up right now, and I get roughly $200 every other week per paycheck (yey college jobs), so whatever I plan on purchasing, I should have enough money for it by Christmas, or at least into January. What are your recommendations for these parts? Was the processor a good choice, or should I have gone AMD? I struggled a bit with deciding on a motherboard, as I wasn't exactly sure what I should be looking for (other than compatibility with my processor and a PCI Express slot for the video card). Any and all comments are welcome.
  9. Easiest way I can think of is to use Sound Recorder. If you're in Windows XP, it's Start->Programs->Accessories->Entertainment->Sound Recorder. Edit->Insert File will allow you to concatenate files together, and you can just record with no sound to insert pauses.
  10. Rainault

    abstract base class and clone

    I don't think inheritance is justified if your only reason for having it is because two classes share the same interface. You should be able to accomplish what you want without inheritance. Also, unless you anticipate an arbitrary number of Image format types other than the two you listed above, I recommend dropping the template argument; instead, in the Image constructor, pass in the Image type you want and store it into a member variable. A simple if statement can change your algorithms based on the Image format. class Image { public: Image(FORMAT initF) : f(initF) {} void DrawLine(...) { /*drawing algorithm*/ } //other methods private: UINT bits; FORMAT f; //other member data }; class DisplayImage { public: void DrawLine(...) { img->DrawLine(...); } //forward to the appropriate virtual functions //other methods, most of them do the same forwarding as DrawLine private: Image *img; }; Quote:I don't really need a clone method, that was a mistake in the choice of name. I really just want a copy method that the user can call when she wants to copy one Image to another That is the purpose of a clone method. Call it what you will, but a clone method (also called the Prototype design pattern, as described above) is used when you want to have a "virtual copy constructor". In other words, you want a copy of a polymorphic type without having to specify what subtype that object is until runtime. Of course, by eliminating the inheritance, you also eliminate the need for a virtual copy constructor, so a regular copy constructor will do just fine here.
  11. Rainault

    abstract base class and clone

    Is an inheritance hierarchy really necessary here? I don't get the point of some of your classes. What does Base represent? What's the difference between Image and DisplayImage? Why does DisplayImage have a pointer to a Base? Give your justifications for these classes; you may need to do a little class redesign. If the only purpose of Base is to provide a pure virtual Copy method, I don't think you really need inheritance here.
  12. Rainault

    abstract base class and clone

    I had thought clone methods were implemented like this: class Abstract { public: virtual Abstract * clone() = 0; }; class Concrete1 : public Abstract { public: virtual Abstract * clone() { return new Concrete1(*this); } }; class Concrete2 : public Abstract { public: virtual Abstract * clone() { return new Concrete2(*this); } }; Abstract * p1; Abstract * p2 = new Concrete1; Abstract * p3 = new Concrete2; p1 = p2->clone(); // p1 now points to a Concrete1 object delete p1; p1 = p3->clone(); // p1 now points to a Concrete2 object delete p2; This way, type safety is preserved.
  13. Quote:1.) In what situation would you want to mark a variable "volatile const"? 2.) In a C preprocessor macro, what does ## signify? 3.) What is the output of this code: int c = 1; c = ++c + c++ + c + ++c; printf("%d",++c); 1) Good question. I've never actually used the keyword "volatile" before. *wanders off to look it up* 2) Token pasting, as stated in an earlier post. 3) As I understand, the correct answer is "undefined". The C standard doesn't allow you to change a variable twice in a single statement, and compilers can interpret that second line differently. Quote:1. Write a function to reverse a string (char array). Optimize it (looking for the use of pointer arithmetic instead of array indexing). void reverse(char * s, unsigned int n) { char * s_end = s + n - 1; while (s < s_end) { *s ^= *s_end; *s_end ^= *s; *s ^= *s_end; ++s; --s_end; } } Quote:2. Which of these calls to your function will work, and why? a) int main() { std::string str = "Hello"; reverse(str.c_str(), 5); } b) int main() { char * str = "Hello"; reverse(str, 5); } c) int main() { char str[] = "Hello"; reverse(str, 5); } a shouldn't work; c_str() returns a const char *, which can't be directly cast into a char *. b and c should work fine, since they do the exact same thing. Quote:3. Implement atoi/itoa. /* Assumes we're in C and can't use C++ libraries or Boost */ #include &lt;ctype.h&gt; int atoi(const char * s) { int result = 0, negative = 0; while (isspace(*s)) ++s; if (*s == '-') { negative = 1; ++s; } while (*s != '\0') { if (!isdigit(*s)) break; result *= 10; result += *s - '0'; ++s; } return negative ? -result : result; } void itoa(int n, char * buffer, int radix) { int nextDigit, bufferSize = 0; while (n &gt;= radix) { nextDigit = n % radix; *buffer = nextDigit + '0'; ++buffer; ++bufferSize; n /= radix; } *buffer = n + '0'; ++buffer; ++bufferSize; *buffer = '\0'; reverse(buffer - bufferSize, bufferSize); } Quote:4. This function returns an approximation (within 1e-6) to the result of a mathematical operation on val. What is that operation? double f(double val) { double app = 1.0; double err = 1.0; while(err > 1e-6) { app = (app * app + val) / (2 * app); err = val/app - app; } return app; } What is the error in the while loop? Without running any test cases or compiling this code, my first guess is that this is a sqrt function. The error in the loop is that the while condition should be "abs(err) > 1e-6".
  14. Rainault

    Help with text based game

    You may want to do something along these lines instead: #include <stdio.h> int main (void) { char a; printf ("You've started your adventure!\n"); printf ("Where do you want to go?\n"); printf (" w = up, a = west, s = south, d = east, p = quit\n"); while (scanf( "%c", &a ) && a != 'p'){ /* %d is used to read ints, while %c is used to read chars. The difference is important. */ if (a == 'w'){ printf ("You've reached an open field.\n"); } else if (a == 'a'){ printf ("You see a sword salesman.\n"); } else if (a == 's'){ printf ("You're in an open field...\n"); printf ("WAIT! The dark castle is ahead!\n"); } else if (a == 'd'){ printf ("There's a broken bridge ahead.\n"); printf ("You must go back.\n"); } else{ printf("Unrecognized character\n"); } printf ("Where do you want to go?\n"); printf (" w = up, a = west, s = south, d = east, p = quit\n"); } printf("Bye bye!\n"); return 0; } The while loop should allow you to continue to accept input from the player, although this code does nothing to update the player's position. You'll probably want to start using functions to handle where the player is currently located. From the look of your code and the way you post, it doesn't sound like you're ready to make a game yet, so I would recommend studying C programming some more before you dive into game making. By the way, I would also recommend reconsidering your aversion to C++ and OOP.
  15. Rainault

    Advancing programming skills

    I would say that paradigm comes after syntax, though you probably should have learned both at the same time. Syntax teaches what you can do with a language, while paradigm tends to teach you what you probably should do. This website has a lot of good FAQs for that, and I hear that the "Effective C++" books by Meyers are also pretty good, too. I definitely agree with Nytegard, though; practice is an essential part of learning how to program. Practice, practice, practice, and don't stop until you... actually, don't ever stop practicing programming. There's always something you could learn.
  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!