389 Posted Topics
Re: This has nothing to do with `const`. If you remove the `const` keyword from your program, you'll get the same error. The problem is that the initializer for a global variable must be a constant. Confusingly the meaning of the word "constant" here has nothing to do with the `const` … | |
Re: A `getUserInput` function simply can not be sensibly defined with that signature. It either has to return something other than void or it has to take its parameters by reference (or pointer), so that it can change them. | |
Re: What's the definition of `o` that you learned? Do you understand that definition? What are your thoughts on how that definition may apply to `a^n = o(n!)`? | |
Re: From the Java docs (emphasis mine): > If n is non-positive then the pattern will be applied as many times as possible and the array can have any length. If n is zero then the pattern will be applied as many times as possible, the array can have any length, … | |
Re: You're only getting one occurence because you're only calling find once. If you use a while-loop instead of an if, you'll call it until it returns false, which will give you all the matches. | |
Re: `1 <= X <= 10` isn't a condition that you're supposed to check in your code. It's just telling you that X will be in that range, so you can take that into account when considering performance or picking data types. It's perfectly okay to ignore that information. The reason … | |
Re: What's `bytearray` and how and where is it defined? Unless you posted this in the wrong forum and this is actually C++ (and `bytearray` is a class that you defined somewhere), I don't understand how the code even compiles (I suppose `temp` might be a macro, but that wouldn't make … | |
Re: > why do most people use brackets in this way when it comes to Java. Because that's what the official style guide recommends. > The second method is obviously easier to read. That's not obvious at all. I imagine that most people will find the style easier to read that … | |
Re: First of all you need to include `string.h`, not `string`, to get the declaration of `strcmp` (or even better keep including `string`, use the string class and don't bother with `strcmp` at all). Secondly `A` is an array of chars, not strings or char pointers, so `A[i]` is a char … | |
Re: The syntax is right, but for template functions the definition needs to be in the header file, not the .cpp file. | |
Re: I don't think it's a good idea to define only one class for all arithmetic expressions and I don't think that's what your TA meant either. What you can do is to define one class that corresponds to the `a1 opa a2`. That class would look like your Add and … | |
Re: Cabin(8) = Cabin(8/2) + 1 = Cabin(4) + 1 = Cabin(4/2) + 1 + 1 = Cabin(2) + 1 + 1 = Cabin(2/2) + 1 + 1 + 1 = Cabin(1) + 1 + 1 + 1 = 0 + 1 + 1 + 1 = 3 That's why the … | |
Re: An abstract syntax tree is a tree where each node represents a syntactical element and each child of a node represents a sub-element of that element. For example for the statement `set x := y + 42;` the AST would consist of an assignment node whose left child node would … | |
Re: The `power` function has three returns. The first is inside the first `if`, the second (which is wrongly indented) is inside the second `if` and the third is outside of any `if`. The third will only execute if none of the previous `if`s were executed (just like the second will … | |
Re: If we just take into account precedence (and not associativity), then all we need to know is the priority of the current operator as well as the one whose operand the current expression is. If the outer priority is higher than or equal to the inner one, we need parentheses. … | |
Re: > but the first sprintf works, the one that writes toDB[0] to param1 The first sprintf causes undefined behavior just like the second does. Some times undefined behavior means that you get a segfault and some times it seems to work fine. That doesn't change the fact that it's undefined … | |
Re: When you say "functor" are you using the term in the C++ sense (i.e. a callable object) or something else? And would a good example be the most simple one that shows you how to create one or something that shows you where they'd be useful? | |
Re: "instead"? Don't you get all four? Anyway what happens is that first the super class constructor is called (causing "B::B(3)"), then the member constructors are called (causing "B::B()" because of your member `b`) and then the body of the constructor is executed (causing the other two outputs). | |
Re: The return type of your `*` operator is `vector`. So when you return a `double` from that operator, it gets automatically converted to `vector` (via your constructor - if you don't want implicit conversion from `double` to `vector`, mark your constructor as `explicit`). However there's no implicit conversion from `vector` … | |
Re: The error means that the `readUser` function expects an argument of type `char*`, but you're giving it a `char`. | |
Re: Your printf format strings don't include any specifiers (like `%s`, `%d`, `%f` etc.). So `printf` does not expect any arguments after the format string, but you do give arguments. These arguments will be ignored and the compiler warns you about this because that's most probably not what you want. | |
Re: > But, why can't we write all the functions directly in .h file and include it in my project files? Because then linking would fail with a "multiple definitions" error if you include the same header into more than one compilation unit (i.e. if you include it from more than … | |
Re: Your variables letter1 and letter2 will always contain the values 'P' and 'Q' respectively (using the given input file, I mean). So doing things like `if(letter1)` doesn't make sense. Inside the loop you should be reading the two truth values on each line into one variable each and then check … | |
Re: > When you say 'member' are you refering to the, what would be an object if the structure were a class or something else? No, he's talking about what comes after the `.` in `foo.bar` (`foo` is the object, `bar` is a member of that object) or in other terms: … | |
Re: `<string.h>` (also available as `<cstring>`) is a C header that declares functions that work on C strings (i.e. 0-terminated `char*`s). The `std::string` class is defined in `<string>`. You'll also need to refer to it as `std::string` as it's located in that namespace. | |
Re: Shifting an `n`-bit integer by `m` bits when `m > n` invokes undefined behavior in C and C++. If you change your code like this, it will give you 0 from count 32 onwards as you'd expect: unsigned int t = 1; for (unsigned int p = 0; p < … | |
Re: If that's all your code, you never give a value to any of your lower-case variables. | |
Re: I haven't read How to Design Programs, so I don't know how good it is, but if you're having success so far, I'd say just stick with it. In my opinion Racket/Scheme is a much easier language to learn than C++, so I wouldn't recommend starting with C++ (though you … | |
Re: A destructor is called (automatically) when an object is destroyed. It does not itself destroy the object. An object is destroyed when it goes out of scope or when `delete` is used on it (in case of objects created using `new`). You should never call a destructor manually unless you're … | |
Re: Can you show us the other files (or rather a minimal version of them that still produces the same error message) in the project and how you build the project? | |
Re: > So I just started using the Goto command Perfect time to stop. > But when I type in follow or Follow it gives me the text that I intend ( You get up and go to the door) but it still gets to the first goto it finds and … | |
Re: Can you show a complete code sample that causes that error? That line looks fine on its own. | |
Re: You don't link individual functions - you link files. If all your files are added to the same project, the compiler (or rather the linker) will link all your files together. If you get error messages about missing definitions, that means that the file with the missing definition is not … | |
Re: > So how do I do the do while NOT thing `while(!thing)` > Perhaps a switch -- case statement will do the trick here. You can't switch on strings. And even if you could that would not help with looping. | |
Re: Why are you trying to cast a string to an int pointer on that line? That is indeed suspicious. | |
Re: You mean, you wrote a program that's asking for a password and using the backspace and delete keys does not work in that program (or at least doesn't work when it's prompting for the password)? So what does happen when you press backspace? Could you show us the code of … | |
Re: If the running time is equal to `n^2 u` for some unit `u`, then you can easily solve for `u` in `10^2 u = 1 second` and then insert the solution in `25^2 u`. If the running time is merely in Theta(n^2) (which is usually what we mean when we … | |
Re: According to [this list](http://msdn.microsoft.com/en-us/library/hh567368.aspx) Visual Studio did not support initializer lists until version 2013. So you just won't be able to use this feature with your version of Visual Studio. | |
Re: `sizeof(states)` gives you the number of bytes in the array. The number of bytes in an array equals the number of elements times the number of bytes per element. The elements in `states` are char pointers and apparently pointers have 4 bytes on your platform (so you're running a 32-bit … | |
Re: > I don't know why it gave me that portion of code if it's unusable `fn` is *unused*, not *unusable*. You could replace line 19 with `fn(rNum, ptr)` and thus actually use `fn`. | |
Re: Are you asking why a method defined in Component can take a Color as its argument? Why wouldn't it be able to? It is perfectly common for methods to take objects of different in classes as arguments. Even the standard `main` method takes an array of `String`s as its argument … | |
Re: The purpose of the header files is to provide declarations for the functions, so that the compiler knows what their types are. This is necessary for the compiler to properly type check the code and generate the right code for function calls (it needs to know the types to generate … | |
Re: Your first piece of code is illegal. In C89 it's illegal because array sizes need to be compile-time constants, so variables are not allowed. A conforming compile should give an error message or at the very least a warning when compiling in C89 mode. In C99 it's allowed to use … | |
Re: > my question is that when we write applet then we write only methods defination not method calling so i am confuse about this that who call the methods of applets. Think of it this way: When you write a normal Java application you write a main method, but you … | |
Re: As the message says `int& length` is a reference (that's what the `&` means). You can not define a reference without initializing it. That is you need to do `int& length = foo;` where `foo` is an l-value (like a variable, an array access, a member access or a function … | |
Re: Assuming that the intended syntax is "'display', followed by one or more spaces, followed by the name of the file", you read a line of input, check whether the line starts with "display" followed by one or more spaces. If it doesn't, you display a "no such command" error. If … | |
Re: If you do `print(t1)`, you'll use the `__str__` method that you defined. The reason that it's not being called when you do `print(t1.increment(300))` is that `increment` returns an integer, not a `MyTime`, so `print` prints it using the normal rules for printing integers. To fix this you should probably make … | |
Re: As the error message says, tuples don't have a `between` method, so you can't do `t.between(...)` where `t` is a tuple. You can call `between` on `MyTime` objects because you defined a `between` method for the `MyTime` class. So if you create an object of that class (by using `MyTime(...)`), … | |
Re: > I only ask this because because references have their own individual definitions of the objects fields that are not shared between other references. What exactly do you mean by that? |
The End.