c++

Basic C++ Recursion program questions

//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)?(с++)

How to create some class from dll(constructor in dll)?(с++) or how to dynamically load class from dll? ...

const_cast in template. Is there a unconst modifier ?

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

Softball C++ question: How to compare two arrays for equality?

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

Why and Where do we use down casting?

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

Difference between CC, gcc and g++?

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

What does vectorization mean?

Is it a good idea to vectorize the code? What are good practices in terms of when to do it? What happens underneath? ...

How do I count how many milliseconds it takes my program to run?

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

How to overload opAssign operator "globally" in C++

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

Impersonation and Registry Manipulation in Vista\Win7

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

Class naming and namespaces

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

What book or online resource do you suggest to learn programming C++ in Linux?

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

Template casting issue

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

Declaring and initializing a variable in a Conditional or Control statement in C++

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

Could someone please explain the difference between a "reference" and a "pointer" in this case?

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

UDP socket port allocation failure

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

Bash input/output in C++

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

whitespace identification in 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? ...

Symbols not found error when linking iPhone app in Xcode

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

MS Visual C++ 2008 Express cannot find path

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