I've often seen that people create objects in C++ using
Thing myThing("asdf");
Instead of
Thing myThing = myThing("asdf");
This seems to work (using gcc), at least as long as there are no templates involved. My question now, is the first line correct and if so should I use it?
...
I've just started working on a new C++/Qt project. It's going to be an MDI-based IDE with docked widgets for things like the file tree, object browser, compiler output, etc. One thing is bugging me so far though: I can't figure out how to programmatically make a QDockWidget smaller. For example, this snippet creates my bottom dock window...
Given that it's one of the hard things in computer science, does anyone know of a way to set up a plugable caching strategy?
What I'm thinking of would allow me to write a program with minimal thought as to what needs to be cached (e.i. use some sort of boiler-plate, low/no cost pattern that compiles away to nothing anywhere I might wa...
I've got the following classes:
class A {
void commonFunction() = 0;
}
class Aa: public A {
//Some stuff...
}
class Ab: public A {
//Some stuff...
}
Depending on user input I want to create an object of either Aa or Ab. My imidiate thought was this:
A object;
if (/*Test*/) {
Aa object;
} else {
Ab object;
}
Bu...
There are some new integer types in the Windows API to support Win64. They haven't always been suppoprted; e.g. they aren't present in MSVC6.
How can I write an #if condition to detect if these types are supported by <windows.h>?
(My code needs to compile under many different versions of Microsoft Visual C++, including MSVC6. So I ne...
I have a templated class
Vector<class T, int N>
Where T is the type of the components (double for example) and n the number of components (so N=3 for a 3D vector)
Now I want to write a method like
double findStepsize(Vector<double,2> v)
{..}
I want to do this also for three and higher dimensional vectors. Of course I could just i...
I am pretty proficient with C, and freeing memory in C is a must.
However, I'm starting my first C++ project, and I've heard some things about how you don't need to free memory, by using shared pointers and other things.
Where should I read about this? Is this a valuable replacement for proper delete C++ functionality? How does it work...
I wrote a C++ application (running on Linux) that serves an RTP stream of about 400 kbps. To most destinations this works fine, but some destinations expericence packet loss. The problematic destinations seem to have a slower connection in common, but it should be plenty fast enough for the stream I'm sending.
Since these destinations a...
according to http://www.cplusplus.com/reference/clibrary/cstring/memcpy/ c++'s memcpy takes three parameters: destination, source and size/bytes. it also returns a pointer. why is that so? aren't the parameters enough to input and copy data.
or am i misunderstanding something? the examples don't use the return value
...
I have trouble compiling a class, which has function pointers as member variables. The pointers are to functions which take an instance of a class as argument.
Like
template<class T, int N>
double (*f)(Vector<T,N> v);
I get "error: data member 'f' cannot be a member template" Compiler is gcc 4.2.
Edit
Before using templates I just ...
Guys that is code copied from a book (Programming Windows 5th edition):
#include <windows.h>
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
MessageBox (NULL, TEXT ("Hello, Windows 98!"), TEXT ("HelloMsg"), 0) ;
return 0 ;
}
Link to the topic in which th...
Hello,
I have got a very, very strange problem in my C++ OpenGL application.
I simply load a texture and apply it to a quadric:
glGenTextures(1, &tex);
glBindTexture(GL_TEXTURE_2D, tex);
glTexImage2D(GL_TEXTURE_2D, 0, 3, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, image);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEARE...
If I do
double d = 34.56;
int i = (int)d;
Am I not "downcasting"?
OR
Is this term only used in terms of classes and objects?
I am confused because in this case we are "downcasting" from a bigger double to a smaller int, but in case of classes, we "downcast" from a smaller base class to a bigger derived class.
Aren't these two c...
I have large (hundreds of MB or more) files that I need to read blocks from using C++ on Windows. Currently the relevant functions are:
errorType LargeFile::read( void* data_out, __int64 start_position, __int64 size_bytes ) const
{
if( !m_open ) {
// return error
}
else {
seekPosition( start_position );
DWORD bytes_read;
BOOL...
I want to create a program that will parse text for key words and make these words a certain color. What type of control supports many different colors? Would I have to create my own, or override the OnPaint() of a basic control or something? (Id like to avoid making my own control from scratch)
Thanks
...
Hi all,
I've written a little file-transfer application written in C++ using Qt 4.x ... it logs into a server, shows the user a list of files available on the server, and lets the user upload or download files.
This all works fine; you can even drag a file in from the desktop (or from an open folder), and when you drop the file icon in...
I know how to add integers to strings, but I'm not sure I'm doing it in an efficient matters. I have a class where I often have to return a string plus an integer (a different integer each time), in Java I would do something like
public class MyClass {
final static String S = "MYSTRING";
private int id = 0;
public String getStrin...
Hello,
When trying to read tokens from a file in C++, I receive a seg fault. Just to play with some things, I tried reading over the file and just printing and surprisingly if you uncomment the code for the first file read and then read the second file everything works fine. If you leave the commented code commented, you receive the seg...
Hi all,
I am writing a video game, Humm and Strumm, which requires a network component in its game engine. I can deal with differences in endianness easily, but I have hit a wall in attempting to deal with possible float memory formats. I know that modern computers have all a standard integer format, but I have heard that they may not...
I have several dozen objects exposed through COM interfaces, each of which with many methods, totaling a few hundred methods. These interfaces expose business objects from my app to a scripting engine.
I have been given the task of protecting every single one of these methods from exceptions being thrown (to catch them and return an er...