User Profile
Collapse
-
Very good advice. But if she just wants a program that encrypts his files, and not necessarily program it herself, there's lots of programs available for free. Even if a very simple cipher like XTEA or RC4 is used, it's not trivial to make a secure implementation.... -
Private inheritance is (or should be) used if you want to use your base class as an implementation detail in your subclass, whereas public inheritance is used to model IS-A, per the Liskov Substitution Principle. This is a prerequisite for being able to use the subclass polymorphically in place of a base. (If you inherit privately you have to explicitly grant friendship to every function and class that wants the same behavior)....Leave a comment:
-
You need more logic than is present in a typical ALU. In particular, logic for doing sign-magnitude conversion, round-to-nearest, and the encoding of subnormal numbers as described above.
It is true that you do not have to implement conversion. My mistake....Leave a comment:
-
what if you write this? :)
[CODE=java]
int j = 42;
double d = 55.64;
double result = d + j;
[/CODE]...Leave a comment:
-
I agree that what you describe is a form of polymorphism, but I disagree that it is the most common form. If you use private inheritance, only the members of Derived (and friends) can use the class polymorphically in place of a Base class.
Inheriting publicly with the Derived class overriding Base's virtual functions we can use a Base* polymorphically through late binding, and I'd say that's how polymorphism is usually implemente...Leave a comment:
-
Of course, but since this is a typical "trick question", wouldn't one expect the answer to be very concise? I know I would.
Floating point addition is much more complicated than simply doing a bitwise add w/carry and convert to two's complement.
You have to convert the the exponent from sign-magnitude form to 2's complement without using arithmetic operators. The easiest way to do this would probably...Leave a comment:
-
Actually, this is C++/CLI so it rightfully belongs in the .NET section....Leave a comment:
-
if the two variables are of type float or double, you would have to implement IEEE-754-conforming addition without using arithmetic operators. It could probably be done, but the resulting code would certainly not be "a small java program".
So if the question is: "How do you make a small java program that calculates the sum of two variables without using arithmetic operators?", my answer is: "It can't be d...Leave a comment:
-
Thanks for your reply. I realize, of course, that my example code demonstrates questionable design. In general I would not use public inheritance unless I intend to use the base class polymorphically , and certainly not if it doesn't have a single virtual function/dtor.
Even if my question was only related to the syntax of the using-declaration, you bring up some good points related to class design that I believe more people than...Leave a comment:
-
Looks like a trick question to me, unless you have omitted some code from your example. Otherwise it is not valid Java, since every function must belong to a class....Leave a comment:
-
Actually the code is not really supposed to do anything, I just tried to make my code example as concise as possible. The intent is to grant access to the doSomething() method that would otherwise be hidden from a Derived object, like so:
...Code:int main() { Derived<int> d; d.doSomething(); // <-- calls Base::doSomething(), //need a using-declaration for this d.doSomething(42);Leave a comment:
-
Is this valid C++?
The following code compiles on the latest VC++, not EDG or MINGW.
...Code:template <typename T> class Base { public: void doSomething(); }; template <typename T> class Derived : public Base<T> { public: using Base::doSomething; // <-- valid? // or do you have to do this? //using Base<T>::doSomething; -
It's very easy to make mistakes like that with arrays, often with catastrophic consequences. To avoid such problems, you might want to consider using an std::string instead, unless there's a good reason not to....Leave a comment:
-
You can just pass the length of the array as the second parameter.
If this is C++ I recommend using a STL container like vector instead of an array....Code:void my_function(BYTE* input, unsigned int len) { // do something }Leave a comment:
-
Slight correction: If your T is a class-type the program may crash because the destructor is called on an object that was not properly copy-constructed.
If your T contains pointers (and a dtor), chances are you also need to make a copy ctor (and assignment operator) that properly creates a deep copy of your object, because vector uses the copy ctor internally.
Otherwise your T's dtor's will end freeing the same memory...Leave a comment:
-
I don't see why this shouldn't work, assuming of course that your vector is an std::vector<T>, where T is a built-in type (like int or long).
However, if your T is a class-type, the program may crash because the destructor is called on an uninitialized object.Leave a comment:
No activity results to display
Show More
Leave a comment: