sepp2k 378 Practically a Master Poster

You're never actually compiling the code. You need to call make to create perl and the other binaries you're trying to copy.

sepp2k 378 Practically a Master Poster

In this case, replacing the &&s with ||s (i.e. "keep running while at least one of the HullShip variables is greater than 0) would have worked too.

sepp2k 378 Practically a Master Poster

The expression condition ? then_expression : else_expression evaluates to the result of then_expression if condition evaluates to true and to else_expression otherwise.

So the above expression evaluates to 1 if f is 0 and to f * fact(f-1) otherwise.

sepp2k 378 Practically a Master Poster

As for Linux, you can look for up-stream repositories that carry bleeding-edge GCC versions, or you can build it from source (as I do).

FWIW Arch Linux has gcc 4.7.1 in its main repository.

sepp2k 378 Practically a Master Poster

As I said, it's a new feature in C++11. It looks like either your compiler does not yet support C++11 or you didn't enable that support. If you're using g++, you need to add -std=c++11 to the command line (or enable the appropriate settings in your IDE).

Once you've fixed that, you'll still get error messages, but they won't be about your usage of using. Specifically you're using matrix where you meant to use array a couple of times. Also you can't use vectors as operands to cout <<.

sepp2k 378 Practically a Master Poster

using my_type = old_type is a new syntax in C++11 which is basically the same as using typedef old_type my_type, with the important difference that it can be templated (whereas typedefs can't be).

So in the code you've shown, matrix<T> is defined as an alias for vector< vector<T> > (for all types T).

sepp2k 378 Practically a Master Poster

The easiest solution would simply be to sort the strings by length (using Java's built-in sort method) and then simply take the first three (or last three depending on the order in which you sorted) strings from the sorted array.

That solution would be much shorter, simpler and easier to understand than yours. However it's O(n log n) whereas your solution is O(n) - also if this is Homework, using sort might count as cheating.

To simplify your solution, the first step would be to do it in one single loop, instead of having three separate methods that all look the same except for some adjustments to the looping logic. To do this you should have three variables, keeping track of the longest, second longest and third longest string respectively. Then for each string you simply check whether it's longer than the longest, second longest or third longest string and, if so, adjust the variables accordingly.

JamesCherrill commented: Excellent reply +14
sepp2k 378 Practically a Master Poster

Because most C implementations don't perform bounds checking when accessing an array. So when you give an index to an array, that index (multiplied by the size of the element type according to the rules of pointer arithmetic) will simply be added to the address where the array begins and the item at the resulting address will be accessed. If that address is one that you're allowed to access, it will give you a value. If it isn't, you'll get a segmentation fault.

That said accessing an array out of bounds is undefined behavior and anything could happen.

Also note that if arr is actually a pointer inside another array (e.g. int base_arr[] = {1,2,3,4,5}; int *arr = base_arr+2;), -2 might very well be a valid index. In that case arr[-2] will have a fully defined value (in the example I gave it would be 1).

sepp2k 378 Practically a Master Poster

None of the variables in your loop ever change, so you get the same output on each iteration of your loop. For example you set rembalance to balance - principle. Since balance and principle are never changed, balance - principle will evaluate to the same value every time, so rembalance will have the same value every time.

If you want to output different values at each iteration of the loop, at least one of the variables used in the loop needs to be changed inside the loop. Presumably that variable should be balance.

sepp2k 378 Practically a Master Poster

they have given only upto 3*3 matrix

They also have a section on n*n matrices right after the one about 3*3.

sepp2k 378 Practically a Master Poster

Does the explanation on Wikipedia help you?

If not, could you maybe rephrase your question to be more specific?

sepp2k 378 Practically a Master Poster

"In file included from ..." is not the error. It tells you where the error occurs. The actual error message comes after that.

Anyway an std::map is a sorted map and thus needs its keys to be comparable to each other. So if you want to use a given type as the key of a std::map, the type either needs to have an operator< defined or you need to supply a custom comparison function (or functor) when creating the map.

sepp2k 378 Practically a Master Poster

If your path doesn't start with a drive letter or a (back- or forward-)slash, it's interpreted relative to the current directory. So Chophouse is right, you need to make your path absolute unless Users is a subdirectory of your current directory.

You also need to escape your backslashes or use forward-slashes instead. Otherwise \U is interpreted as the beginning of a unicode escape sequence, which is why you got a unicode error.

sepp2k 378 Practically a Master Poster

That really depends entirely on the context.

sepp2k 378 Practically a Master Poster

First of all a isn't a pointer, it's an array. It decays to a pointer in certain contexts, but it decays to a pointer to an int-array, not a pointer to an int, so you need to cast it if you want to use it as an int-pointer.

And yes, a+1 would give you a pointer to the second row of a. However you're not doing a+1, you're doing (int*)a + 1. So you cast a to a pointer to an int, not an array. So incrementing it by 1 will cause it to point to the next int, not to the next row. Basically a is used as if it was a flat array instead of an array of arrays on line 2. So the pointers in p point to 1, 2 and 3 respectively.

sepp2k 378 Practically a Master Poster

You left out the part of other.py where you import main, but if you didn't use the from main import ... form of import, you'll have to refer to main's variables, functions and classes as main.app etc. instead of just app.

sepp2k 378 Practically a Master Poster

An unchecked exception is one that inherits (directly or indirectly) from RuntimeException. A checked exception is one that doesn't.

sepp2k 378 Practically a Master Poster

If your method calls a method that can throw an IOException (like ImageIO.read does), you either need to catch the exception or declare that your method may throw an IOException too (which you do by adding throws IOException to your method's signature).

You have to do this because IOException is a checked exception and the Java compiler ensures that each method may only throw those checked exceptions that it's been declared to throw using the throws declaration.

The idea behind this is that you're always aware if there's a possible error condition that you do not handle.

And yes, there are other methods in other classes that throw checked exceptions, too. Pretty much all IO-related methods can throw IOExceptions. And there of course are other checked exceptions as well that need to be handled the same way.

sepp2k 378 Practically a Master Poster

Is there any way to make A work without using new (that includes placement new)?

No, non-POD classes can not be allocated dynamically without using new. As far as the standard is concerned, it's undefined behavior to not use new.

In practice the problem is, as you suspected, the vtable. malloc returns uninitialized memory, so the object's vtable pointer will point somewhere random instead of to shazbot's vtable.

May I ask why you want/need to avoid using new?

PS: You shouldn't use explicit casts to perform an upcast. That makes it harder to see when you perform a cast that's actually unsafe. Also you should prefer C++ style casts over C-style casts in the cases where you do need an explicit cast.

sepp2k 378 Practically a Master Poster

Actually for me the decryption seemed to work fine-ish (the third.txt file contained the original file's contents repeated multiple times). However after finishing decrypting, it goes back to main and causes a segmentation fault on line 90.

This happens because you mix getline and operator>>. After decrypts uses cin >> to read n and c, there will still be a newline character in the stream. Then when main calls getline, getline gives you an empty line because the first thing it sees is that newline character. So then you put that empty line in a string stream and populate vstring from that. So vstring will be empty. And when you try to access vstring[0] on line 90, you get a segmentation fault.

sepp2k 378 Practically a Master Poster

Have you tried to run your code in the debugger to find out which line the segmentation fault happens on? Have you tried to run your code through valgrind to find out when and where you write to or read from invalid memory?

Also can you give us some sample input we can enter into your program to reproduce your error?

sepp2k 378 Practically a Master Poster

When you call a method, you don't spell out the type of the arguments - you only do that when declaring the method. I.e. if you want to call drawHexagon with width as its argument, you write drawHexagon(width) not drawHexagon(int width).

That said, unless the SimpleTurtle class has a static variable called width, the width variable isn't defined anywhere in your program. So you need to define it and set it to a sensible value before you can use it.

Also you're missing a semicolon on line 105 (that part of the error message was pretty clear, I think).

sepp2k 378 Practically a Master Poster

There's nothing in your code that would reset the value of plus. However with your constructors the way they are, there is no way to create a tuna object that has the numbers as well plus set to a meaningful value.

So I'm guessing when you use your code, you're actually creating two tuna objects: one with the correct value for plus and one with the correct values for num1 and num2. Since each object has its own instance variables, one object's value for plus won't affect the behavior of the other object.

sepp2k 378 Practically a Master Poster

That's because your code in printScore doesn't check whether the user entered 'q'. Only your code in main did. If you handle the user input in printScore, you need to move the code that handles the user entering 'q' in printScore as well.

sepp2k 378 Practically a Master Poster

There is nothing you can do to make newtype f = 1 work. Java doesn't allow implicit conversions for non-primitive types. There's also no way to make arithmetic operators like + etc. work with your newtype class.

Using a user-defined number class will always look different than using primitive numbers in Java - you can't avoid that. That's why code using the BigInteger class is so ugly.

sepp2k 378 Practically a Master Poster

No, it just means that humanChoice will return even if the user enters invalid input. Qutting with 'q' shoudl work fine (at least I can't see why it wouldn't at the moment).

sepp2k 378 Practically a Master Poster

You're asking the player for his choice (by calling humanChoice) twice: Once in main and once in printScore.

PS: On line 24 you will always break because the condition choice == 'Q' || 'q' is always true (because 'q' is true).

sepp2k 378 Practically a Master Poster

There are many GUI libraries for Linux/X11. The most popular ones are GTK (the one that Gnome and XFCE use (among others)) and Qt (the one that KDE uses). Both of them run on all major platforms, not just X11.

sepp2k 378 Practically a Master Poster

You have allocated the array of poitners rowptr, but not the elements of each row.

Not true. He allocated enough memory for all the rows on line 14. He's then making each pointer in rowptr point to one row inside arrayptr on line 17. So that part's fine.

sepp2k 378 Practically a Master Poster

Your types are wrong. Your compiler should have warned you about that. If it didn't, increase your warnings level - that will save you a lot of pain in the future.

arrayptr and rowptr should have types char* and char** respectively. Since you made arrayptr and int-pointer, your second for loop will iterate int-by-int, not char-by-char. So it's skipping over characters because ints are bigger than chars.

sepp2k 378 Practically a Master Poster

a) In Java we usually speak of "object references", not "memory addresses". Memory addresses are a low-level concept that isn't really visible to Java programmers. But yes, when you pass m2 to the Mixer constructor, you're passing a reference to the object that m2 refers to. So the m1 variable of the newly creater Mixer object will refer to the same object as the variable m2.

b) m1 is an instance variable of the Mixer class. So each Mixer object has its own variable called m1. Writing someMixerObject.m1 will access the variable m1 that belongs to that Mixer object.

c) If a Mixer object is created using the default constructor, its m1 variable will be null (because the default constructor does not set m1). If it is created using the one-argument constructor its m1 variable will be the argument passed to that constructor.

So when you create m2 in your main method, its m1 variable is null because you used the default constructor. m3's m1 variables is equal to m2 because you used the 1-argument constructor with m2 as the argument. So when you do m4 = m3.m1, m4 will be equal to m2. And when you do m5 = m2.m1, m5 will be equal to null because, as already said, m2's m1 variable is null.

Since you're not allowed to call methods on null, you get an exception when you invoke m5.do().

JamesCherrill commented: Very clear and comprehensive reply +14
sepp2k 378 Practically a Master Poster

You're getting the parse error because you forgot a semicolon on line 2. Whenever you get "Unexpected blabla" at the beginning of a line, there's a good chance that you forgot a semicolon on the line before.

sepp2k 378 Practically a Master Poster

booleanExpression ? true : false is just a more clumsy way of writing booleanExpression. Other than that (and not using std::string), I don't see anything that needs improvement.

Edit: On second thought you can simplify your setter methods by doing foo = temp_foo; after doing delete [] foo; instead of mallocing memory, strcpying and deleting a second time.

sepp2k 378 Practically a Master Poster

Your copy constructor calls your setFoo methods. Your setFoo methods use delete on the old value of the variable that they're setting. When the copy constructor is invoked, the variables won't have old values because the object is brand new. That means that your setFoo methods will call delete on uninitialized pointers. This makes your program crash.

The quick fix would be to set your pointers to NULL in the copy constructor before you invoke your setter methods (deleting a null pointer is safe). A better solution would be to get rid of your char pointers altogether and use std::string instead.

Lucaci Andrew commented: std::string is the way +5
sepp2k 378 Practically a Master Poster

You can use the str_replace function to replace each occurence of "." in $description with ".\n", i.e. to insert a newline (\n) after each period. If you want to display your string as HTML, you should use "<br>" instead of (or in addition to) "\n".

Synestic commented: Thanks +0
sepp2k 378 Practically a Master Poster

The problem is unrelated to the fact that test takes a variable number of arguments. The problem is that you're calling test as if it was a method of the VariableArguments1Test class, which it's not.

If you want to call a static method of another class, you'll need to specify the class when calling it (or use a static import). So you need to write VariableArguments1.test instead of just test.

sepp2k 378 Practically a Master Poster

csc.exe is the C# compiler that comes with Microsoft's .net SDK. mcs is the C# compiler that comes with Mono. Neither of these ship with MonoDevelop, but you need to have one of them installed in order to use MonoDevelop.

So if you want to find csc.exe, you should look in the directory where you installed the .net SDK, not in the directory where you installed MonoDevelop. And if you're not on Windows, you should be looking for mcs instead (which will presumably be somewhere in your PATH).

sepp2k 378 Practically a Master Poster

@Fulctrum Your first input function is broken - it returns the address of a local variable.

sepp2k 378 Practically a Master Poster

Image.FromStream throws an ArgumentException if you call it with null as an argument or if the given stream does not contain an image in a valid (and supported) format.

Since you set streamImage on the line above, it is probably safe to assume that it is not null. So the likely explanation is that the data in byteImage is badly formatted or corrupted.

sepp2k 378 Practically a Master Poster

Your code doesn't seem to match your description at all. You said the function should return a Rectangle, but the function in the code actually takes a rectangle (that it never uses) and returns an int.

Your function also calculates the area of the rectangle that the user entered which your description didn't say anything about. The calculation of the area should really happen in its own function.

PS: In C++ you don't need the struct keyword when declaring variables or parameters of a struct type.

TrustyTony commented: Observant, good suggestion to separate calculation and printing +12