Hey guys, I had some questions about using inline. I have been told to use it on small functions that I use a lot but I want to understand exactly how it works. Here is just a snippet of how I use it.
static inline point3D createPoint3D(GLfloat x, GLfloat y, GLfloat z){
point3D newPosition;
newPosition.x = x;
newPosition.y = y;...
Hey guys, I had some questions about putting f next to literal values. I know it defines it as a float but do I really need it?
Is this 2.0f * 2.0f any faster then 2.0 * 2.0? and if I have a variable like float a = 2.0;
is this 2.0f * a any faster then 2.0 * a?
...
So I just spent the last few hours pouring over code trying to figure out the source of a bug only to find that my error was none other than the obviously wrong but compiler accepted:
if (a = b)
where it should have been
if (a == b)
What do you guys do to safeguard against these frustrating errors? What other common "obviously wro...
This may be a silly question, but nothing comes to mind straight away. Given a list R of 2D rectangles (x, y, w, h) arranged so that any given rectangle is either fully inside or fully outside any other, what's the most efficient way to determine the immediately enclosing rectangle p of each rectangle in R? Currently I sort R by y then x...
// ExampleCodes.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include<stdio.h>
#include<iostream>
using namespace std;
char* stringReverse(char* s)
{
char temp, *p,*q;
q = s;
while( *(++q));
for( p = s; p < --q; p++)
{
temp = *p;
...
So I'm making a snake game with teleports and the usual mice. I had a loop running like this:
while(snake.alive() && miceEaten < micePerLevel)
{
displayInfo(lives, score, level, micePerLevel - miceEaten);
//some code
if(miceEaten())
{
//update score...
}
//more stuff...
}
The problem with the above code...
Hello,
i'm currently trying to build an add-in which is similar to VSNewFile. So it's just a simple extension which provides a faster way to create new files. The problem with VSNewFile is that it doesn't work for C++ projects and i need it for that.
Here is my problem:
I'm unable to retrieve the absolute path of a selected directo...
Subject is self-explaining
...
Sorry if this is explicitly answered somewhere, but I'm a little confused by the boost documentation and articles I've read online.
I see that I can use the reset() function to release the memory within a shared_ptr (assuming the reference count goes to zero), e.g.,
shared_ptr<int> x(new int(0));
x.reset(new int(1));
This, I believe ...
Does Qt have a built-in way to inflate or grow a rectangle? Like .NET's Rectangle.Inflate or Java's Rectangle.grow... or do I have to implement my own? I've looked through the docs and couldn't find one but maybe I'm missing something.
...
hi,
I heard auto_ptr is being deprecated in the new C++. What is the reason for this.
Also I would like to know difference between auto_ptr vs shared_ptr
...
What is the difference between aio_write() and O_NONBLOCK write()?
Also, I use write() to a text file using file descriptor using the O_NONBLOCK function and compare the performance with the aio_write() by putting a timer before and after the function.
It seems that the write() function would take longer time to write to file when the...
If I dont define my own constructor is there any difference between Base *b = new Base; vs Base *b = new Base(); ?
...
Hi, I'm newbie in programming especially c and c++.
I often saw VARNAME_P and VARNAME_T in c/c++.
What are the difference between those two?
Thanks in advance
...
What I am doing is opening my file using fstream at the start of the main and closing it at the end. In between I am writing "Hello World" and after that reading what I wrote but the result is always weired charecters and not the "Hello World". I did do a cast to char but that didnt help. Any way I can do this?
...
How can I reboot in c++? Is there any provision in WinSDK? What kind of rights should my program(process) have to do so?
...
What is the problem with this code ? this code is giving me lots of syntax errors. Also I would like to know why functors are used in C++.
class f
{
public:
int operator(int a) {return a;}
} obj;
int main()
{
cout << obj(0) << endl;
}
...
I would like to know what is the difference between static variables in a header file vs declared in a class. When static variable is declared in a header file is its scope limited to .h file or across all units. Also generally static variable is initialized in .cpp file when declared in a class right? So that does mean static variable s...
I writing code that should compiled and run on both Windows and unix like Linux. I know about difference between line endings, but question is which to prefer for my code? Does it matter? I want it to be consistent - say all my code uses LF only, or is it better CRLF only? Are there critaria for comparing?
If it matters mostly I care fo...
I've a program which links to many libraries. g++, by default, prefers to link to shared libraries , even if corresponding archive exists. How can I change this preference to prefer static archive over dynamic libraries , if a static archive exists. Note , I used '-static' option, but it tries to find static archive for all libraries whi...