//This program finds the GCD of two numbers using a recursive function call via the
//Euclidean algorithm
#include <iostream>
#include <cmath>
using namespace std;
int GCD (int A, int B);
int main()
{
int A = 45, B = 55;
cout << "The GCD is " << GCD(A,B) << endl;
//test
return 0;
}
int GCD (int A, int B)
{
A = ab...
How to create some class from dll(constructor in dll)?(с++)
or how to dynamically load class from dll?
...
I have a template class like this:
template<T>
class MyClass
{
T* data;
}
Sometimes, I want to use the class with a constant type T as follows:
MyClass<const MyObject> mci;
but I want to modify the data using const_cast<MyObject*>data (it is not important why but MyClass is a reference count smart pointer class which keeps the re...
I am trying to compare two int arrays, element by element, to check for equality. I can't seem to get this to work. Basic pointer resources also welcome. Thank you!
int *ints;
ints = new int[10];
bool arrayEqual(const Object& obj)
{
bool eql = true;
for(int i=0; i<10; ++i)
{
if(*ints[i] != obj.ints[i])
eql = ...
Are there any cases where we do down casting of objects?
If we do, why?
I have observed a way of hiding implementation using the below code. Is this the correct way to do? Is there any better way to achieve the same.
class A{
public:
A();
virtual ~A();
//exposed virtual functions
};
class AImpl : public A{
p...
What are the difference between the 3 compilers CC, gcc, g++ when compiling
C and C++ code in terms of assembly
code generation, available libraries, language features, etc.?
...
Is it a good idea to vectorize the code? What are good practices in terms of when to do it? What happens underneath?
...
This will show how many seconds:
#include <iostream>
#include <time.h>
using namespace std;
int main(void)
{
int times,timed;
times=time(NULL);
//CODE HERE
timed=time(NULL);
times=timed-times;
cout << "time from start to end" << times;
}
This will show how many ticks:
#include <iostream>
#include <time.h>
us...
Just curious about how to overload them.
The opAssign operators are like addAssign(+=) and subAssign(-=).
"globally" means they are not overloaded as member functions, but just a operator act on operands
For these opAssign operators, they are binary operators.(they receive two operands)
Therefore two parameters are needed.
I found n...
I need to create a program that has access to HKLM when running in a non-admin session. I have access to the admin credentials so impersonation seems to be an option.The sequence of Win32 calls is:
LogonUser
ImpersonateLoggedOnUser
RegOpenKeyEx
RegCreateKeyEx
The key is successfully created on XP/2003 and fails with 'Access Denied' ...
Will using same class name within multiple namespaces get me into trouble? I also try to remove dependency to math library. What do you think about following design.
first file
#define MATH_RECTANGLE_EXISTS
namespace math {
class Rectangle : Object2D {
public:
float perimeter();
float area();
float...
I have years of C++ programming experience in Windows. Now I need to program some applications for Linux. Is there any resource that helps me quickly get the required information about Linux technologies available to C++ developers?
...
I seem to be getting an error in the below code when I attempt to cast to a template of class T, when T is of type float. I have realized already that a type of int functions correctly, because the following is valid syntax:
char* str = "3";
int num = (int)str;
The same is not true of float. I'm wondering if there is a way to stop th...
In Stroustrup's The C++ Programming Language: Special Edition (3rd Ed), Stroustrup writes that the declaration and initialization of variables in the conditionals of control statements is not only allowed, but encouraged. He writes that he encourages it because it reduces the scope of the variables to only the scope that they are requir...
When I read litb answer to this question, I learned that passing an array by reference allows us to obtain its size. I just played little bit with code, and tried to pass a "function" by reference and surprisingly (at least for me), this code compiles:
void execute( void (&func)() ) // func is passed by reference!
{
func();
}
Is t...
Hi
I am creating a winsock UDP program. code i am using is shown below.
I am always getting port assignment error.
I am not able to understand why port always allocated is zero. If some can help me with this....
void UDPecho(const char *, const char *);
void errexit(const char *, ...);
#define LINELEN 128
#define WSVERS MAKEWORD(...
Hello,
I'm writing program in C++ (for XAMPP communication) and I want to execute command which I have in strings (I know that this is simply system("command")) but I want to get the output from bash to C++ to string. I've founded several threads about this, but no which solved Bash -> C++.
...
My code has to identify whitespace characters using cin, so when I use space as an input it should identify the space. How do I do this?
...
Whenever I try to compile my iPhone app which i am porting I get linking errors. The app uses a scripting language called Squirrel (to read the level files, fine by the SDK, no user input). I have linked all the libraries including libsquirrel.a. What am I doing wrong?
(App is SuperTux, source code at supertux.lethargik.org for computer ...
I'm trying to do something basic
#include <iostream>
using namespace std;
int main()
{
cout << "Hello, World!";
return 0;
}
After using F7 I get
1>mt.exe : general error c10100b1: Failed to load file "..\Debug\helloworld.exe". The system cannot find the path specified.
So it cant find the file that it'll eve...