Search Results

Showing results 1 to 40 of 43
Search took 0.01 seconds.
Search: Posts Made By: grumpier
Forum: C++ Jan 14th, 2009
Replies: 8
Views: 543
Posted By grumpier
I'd be betting on your side. But that just means he then needs to define the criterion for "The most efficient". For example, does it mean "fastest", "smallest number of machine instructions",...
Forum: C++ Jan 14th, 2009
Replies: 8
Views: 543
Posted By grumpier
You're developing a realtime application, and don't know how to add values to elements of an array?????

Pull my other leg: it'll play a tune for you.

What is the criterion by which you would...
Forum: C++ Jan 11th, 2009
Replies: 4
Solved: casting
Views: 405
Posted By grumpier
An explicit conversion is what you're calling a cast. An implicit conversion is a conversion between types that the compiler allows or performs, even if you don't do a cast. For example;

...
Forum: C++ Jan 11th, 2009
Replies: 4
Solved: casting
Views: 405
Posted By grumpier
As a general rule, yes you should.

An implicit conversion exists between int and size_t so, in rough terms, you shouldn't need an explicit conversion between them.

Note "explicit conversion" is...
Forum: C++ Jan 11th, 2009
Replies: 3
Views: 995
Posted By grumpier
Try this. Comments added explaining the reason for change from your code.

#include <iostream> // <iostream> is standard, <iostream.h> is not
#include <cstring> // need functions to...
Forum: C++ Dec 29th, 2008
Replies: 3
Views: 792
Posted By grumpier
If the content of header A relies on content of header B, then it is generally a good idea for header A to #include header B. Examples of "relies on" are;

- header B declares a base class, and...
Forum: C++ Dec 27th, 2008
Replies: 15
Views: 2,751
Posted By grumpier
You need to understand the difference between registering a callback function and actually calling it.

Setting TButton's OnClick event egisters a function that will be called when the user -...
Forum: C++ Dec 26th, 2008
Replies: 15
Views: 2,751
Posted By grumpier
TButton's constructor needs to be passed a pointer to a TComponent (eg a parent form) that is responsible for managing the button.

It is also necessary to set various attributes: position,...
Forum: C++ Dec 17th, 2008
Replies: 6
Views: 1,299
Posted By grumpier
The only way in which a constructor can report an error is by throwing an exception.

The C++ standard has this to say (in Section 15.2 "Constructors and destructors" which is within Section 15...
Forum: C++ Dec 15th, 2008
Replies: 4
Views: 494
Posted By grumpier
That statement is inaccurate on so many levels that I'm speechless. Non-virtual functions can also be overridden, but the behaviour differs from overridden virtual functions due to "name hiding", as...
Forum: C++ Dec 13th, 2008
Replies: 5
Views: 459
Posted By grumpier
In an ideal world, where compiler vendors care about perfectly diagnosing all errors in code, yes. In the real world, where compiler vendors prefer to focus attention on other things (eg...
Forum: C++ Dec 10th, 2008
Replies: 3
Views: 2,199
Posted By grumpier
It is necessary for the derived class to override all inherited pure virtual functions, otherwise the derived class remains an abstract class.
Forum: C++ Dec 10th, 2008
Replies: 3
Views: 2,199
Posted By grumpier
Provide a small but complete example of code that exhibits your problem.

Your code sample and description is not complete, and the cause of the error is probably in something you haven't shown or...
Forum: C++ Dec 4th, 2008
Replies: 2
Views: 285
Posted By grumpier
Your problem is actually the first four lines of the main() function. I've added comments to the code that are related to problems on each line.

void main() // main should return int, not...
Forum: C++ Nov 30th, 2008
Replies: 3
Views: 500
Posted By grumpier
The C++ standard explicitly allows compilers to eliminate temporary objects if the only way of detecting if those temporary objects exist is to track constructor and destructor calls.

A special...
Forum: C++ Nov 27th, 2008
Replies: 8
Views: 834
Posted By grumpier
Your main.cpp needs to have visibility of the definition of the conversion (or cast) operator. In other words, the implementation of the operator needs to be inlined into the vector.h: otherwise...
Forum: C++ Nov 26th, 2008
Replies: 2
Views: 337
Posted By grumpier
You are making the mistake of assuming that integer division yields a floating point result - it doesn't: it yields an integer result and integers can't represent fractions.

In your code i/2231...
Forum: C++ Oct 30th, 2008
Replies: 4
Views: 450
Posted By grumpier
If there are common things that all classes which handle triangles have to do, put those functions into their own class (eg TriangleModelFile derived from ModelFile). Derive the specific/multiple...
Forum: C++ Oct 30th, 2008
Replies: 4
Views: 450
Posted By grumpier
Don't use the first option. The whole point of a Base class is capturing functionality that is common to all derived classes.

As to the second option, there are many ways. Such as....
...
Forum: C Oct 28th, 2008
Replies: 22
Views: 1,846
Posted By grumpier
Wash your mouth out with soap. main() returns int.
Forum: C Oct 28th, 2008
Replies: 22
Views: 1,846
Posted By grumpier
I'll answer your question with a question.

Under what conditions will

if ((x < 1 || x > 4) && printf("Goofy"))
{
printf(" is also known as Dippy Dawg");
}

print out "Goofy is also...
Forum: C Oct 27th, 2008
Replies: 22
Views: 1,846
Posted By grumpier
A post-test loop is a generic name for a loop of the form do { ... } while (condition), as opposed to a while(condition) {} loop.

The solution, if you have to do that, is to have the printf()...
Forum: C Oct 27th, 2008
Replies: 6
Views: 818
Posted By grumpier
(1) strtok() assumes both its arguments are strings that are terminated with a 0 character. Behaviour is undefined if that is not true.

2) strtok also returns NULL if it cannot find a token...
Forum: C Oct 18th, 2008
Replies: 24
Views: 8,674
Posted By grumpier
Not even close.

Your code does not insert any characters into the string array. What is the purpose of the "input" argument supplied to the function? where is the codes counting the number of...
Forum: C Oct 18th, 2008
Replies: 6
Views: 787
Posted By grumpier
scanf() would return an EOF in that case.[/QUOTE]
No it will not. It will return zero in that case.

EOF is only returned upon reaching end of input. If there is input in the stream that does...
Forum: C++ Oct 18th, 2008
Replies: 2
Views: 443
Posted By grumpier
Your function highestTest() does not initialise the variable "highest", but the first operation involves comparing its value with elements of the array. That means the value it ends up with in...
Forum: C Oct 14th, 2008
Replies: 10
Solved: printf
Views: 867
Posted By grumpier
Yes. Look up the C standard header stdarg.h or (in C++) the standard header <cstdarg>. Those headers contain macros and types that support writing functions with variable argument lists.
Forum: C Oct 12th, 2008
Replies: 4
Solved: c vs assembly
Views: 952
Posted By grumpier
Apart from that, it often takes a lot more effort to write assembly code to achieve X than it does to do X in a higher level language like C. C also has a library .... which means it is not...
Forum: C++ Oct 5th, 2008
Replies: 4
Solved: vector <char*>
Views: 3,898
Posted By grumpier
When you append pointers onto a vector of char, the pointer is copied. You are expecting the data the pointer points at to be copied.

With a vector<char *> you need to explicitly copy the data...
Forum: C Oct 4th, 2008
Replies: 6
Views: 980
Posted By grumpier
There is also the incidental concern that your function is recursive, which does not meet the requirement to be non-recursive.
Forum: C Oct 4th, 2008
Replies: 8
Solved: Null Char
Views: 2,124
Posted By grumpier
A c-style string (eg a string literal) is an array of char that, by convention, is terminated with '\0'.
Forum: C Oct 3rd, 2008
Replies: 8
Solved: Null Char
Views: 2,124
Posted By grumpier
Because the %s format specifier tells printf() and related function that the corresponding argument is a pointer to char and to keep printing chars until it finds a zero.

When an array is passed...
Forum: C Oct 1st, 2008
Replies: 8
Solved: Null Char
Views: 2,124
Posted By grumpier
That's not true. You have explicitly initialised two elements of three-element array. The standards go about it in a round-about way (there's a logic train to follow to get to the conclusion, and...
Forum: C++ Sep 29th, 2008
Replies: 24
Views: 2,954
Posted By grumpier
Well, I could. But that takes the challenge of problem solving away from you.

Look back in my previous posts in this thread for definition of T, n, etc.

VernonDozier has worked out what I'm...
Forum: C++ Sep 28th, 2008
Replies: 24
Views: 2,954
Posted By grumpier
Start with T(0) = 1.

In a loop use the fact that T(n+1) = x*T(n)/(n+1) to compute each term. Add the terms together.
Forum: C++ Sep 28th, 2008
Replies: 24
Views: 2,954
Posted By grumpier
Oh, please! Huge integer libraries or strings are needed for some things, but falling back on them for basic problems like this is crazy.

The program can go to much higher terms simply using the...
Forum: C++ Sep 25th, 2008
Replies: 7
Views: 560
Posted By grumpier
No .... you mean your tests did not detect a problem. Your tests will only check things you think to test. If you didn't anticipate the particular problem that is occurring, a fault will get...
Forum: C++ Sep 25th, 2008
Replies: 7
Views: 560
Posted By grumpier
The cause of your problem is almost certainly code executed before your red lines are reached.

My guess - although you haven't shown them - is that the problems really occur in your input()...
Forum: C++ Sep 12th, 2008
Replies: 6
Views: 824
Posted By grumpier
Not even close.

You have declared myclass's length() method as taking one argument, and yourlen() calls it with two arguments.

Similarly, yourlen() is declared with no arguments, but when you...
Forum: C Sep 11th, 2008
Replies: 4
Views: 473
Posted By grumpier
Firstly, your variables a, b, and c are uninitialised: their value before entering the loop could be anything.

As to your loop, it doesn't really make sense.

You only need two variables. An...
Showing results 1 to 40 of 43

 


About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC