389 Posted Topics

Member Avatar for bostjanv

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` …

Member Avatar for bostjanv
0
114
Member Avatar for redtribal23

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.

Member Avatar for redtribal23
0
149
Member Avatar for zeedote

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!)`?

Member Avatar for sepp2k
0
200
Member Avatar for nitin1

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, …

Member Avatar for nitin1
0
169
Member Avatar for nikk8a

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.

Member Avatar for nikk8a
0
247
Member Avatar for aida.atef.31

`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 …

Member Avatar for aida.atef.31
0
182
Member Avatar for nitin1

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 …

Member Avatar for Banfa
0
143
Member Avatar for silvercats

> 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 …

Member Avatar for samson.dadson.3_1
0
507
Member Avatar for shahera.arafat

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 …

Member Avatar for sepp2k
0
119
Member Avatar for Mr.UNOwen

The syntax is right, but for template functions the definition needs to be in the header file, not the .cpp file.

Member Avatar for sepp2k
0
347
Member Avatar for Slavi

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 …

Member Avatar for Slavi
0
165
Member Avatar for aluhnev

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 …

Member Avatar for aluhnev
0
265
Member Avatar for Slavi

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 …

Member Avatar for Slavi
0
204
Member Avatar for aluhnev

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 …

Member Avatar for cgeier
0
177
Member Avatar for catastrophe2

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. …

Member Avatar for catastrophe2
0
243
Member Avatar for kyle.mace.35

> 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 …

Member Avatar for rubberman
0
1K
Member Avatar for bumsfeld

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?

Member Avatar for bumsfeld
0
3K
Member Avatar for vergil1983

"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).

Member Avatar for vergil1983
0
183
Member Avatar for shahera.arafat

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` …

Member Avatar for shahera.arafat
0
205
Member Avatar for Jeroen Mathon

The error means that the `readUser` function expects an argument of type `char*`, but you're giving it a `char`.

Member Avatar for Jeroen Mathon
0
181
Member Avatar for schzatprodn

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.

Member Avatar for schzatprodn
0
9K
Member Avatar for nitin1

> 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 …

Member Avatar for Lardmeister
0
235
Member Avatar for yaldoo

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 …

Member Avatar for sepp2k
0
4K
Member Avatar for Sahilsikka
Member Avatar for lewashby

> 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: …

Member Avatar for cheryllocascio
0
195
Member Avatar for lewashby

`<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.

Member Avatar for lewashby
0
230
Member Avatar for christinetom

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 < …

Member Avatar for rubberman
0
424
Member Avatar for psichoman5
Member Avatar for woooee
0
468
Member Avatar for MasterChat

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 …

Member Avatar for MasterChat
0
222
Member Avatar for Entalist

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 …

Member Avatar for Entalist
0
185
Member Avatar for davecoventry

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?

Member Avatar for davecoventry
0
5K
Member Avatar for Kris_3

> 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 …

Member Avatar for mike_2000_17
0
204
Member Avatar for Jjajangmyeon

Can you show a complete code sample that causes that error? That line looks fine on its own.

Member Avatar for vijayan121
0
315
Member Avatar for nathan.pavlovsky

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 …

Member Avatar for nathan.pavlovsky
0
470
Member Avatar for Kris_3

> 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.

Member Avatar for Kris_3
0
134
Member Avatar for jtjudge

Why are you trying to cast a string to an int pointer on that line? That is indeed suspicious.

Member Avatar for sepp2k
0
553
Member Avatar for YiLiang

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 …

Member Avatar for rubberman
0
188
Member Avatar for simbamadah

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 …

Member Avatar for mike_2000_17
0
98
Member Avatar for aluhnev

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.

Member Avatar for sepp2k
0
201
Member Avatar for yuimikazuki

`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 …

Member Avatar for sepp2k
0
131
Member Avatar for lewashby

> 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`.

Member Avatar for sepp2k
0
193
Member Avatar for moaz.amin.37

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 …

Member Avatar for stultuske
0
218
Member Avatar for nitin1

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 …

Member Avatar for L7Sqr
0
136
Member Avatar for oanahmed

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 …

Member Avatar for oanahmed
0
349
Member Avatar for moaz.amin.37

> 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 …

Member Avatar for JamesCherrill
0
261
Member Avatar for Jjajangmyeon

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 …

Member Avatar for Jjajangmyeon
0
6K
Member Avatar for archie.herbias

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 …

Member Avatar for archie.herbias
0
2K
Member Avatar for kxjakkk

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 …

Member Avatar for sepp2k
0
265
Member Avatar for kxjakkk

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(...)`), …

Member Avatar for kxjakkk
0
285
Member Avatar for iConqueror

> 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?

Member Avatar for ChrisHunter
0
134

The End.