c++

May a compiler optimize a reference to constant parameter to constant value ?

Consider following function: void func(const char & input){ //do something } Apparently it makes sense for the parameter to be constant value not reference to constant regarding size of the char type, Now may a compiler optimize that to constant value so that it'll be the same as following ? void func(const char input){ //do someth...

Would using a virtual destructor make non-virtual functions do v-table lookups?

Just what the topic asks. Also want to know why non of the usual examples of CRTP do not mention a virtual dtor. EDIT: Guys, Please post about the CRTP prob as well, thanks. ...

Why this scanf returns false?

This scanf should always return true until I input none numeric input, but this scanf never executes while loop. Why? Sample input: 10.0 5.0 Press [Enter] to close the terminal ... Code: #include <stdio.h> #include <stdlib.h> int main(int argc, char** argv) { float a, b; while ( scanf("%f %f", &a, &b) == 1 ) { p...

when is the right time to use *, & or const in C++

hi i was studying pointers references and came across different ways to feed in parameters. Can someone explain what each one actually means? I think the first one is simple, its that x is a copy of the parameter fed in so another variable is created on the stack. as for the other im clueless. void doSomething1(int x){ //code } voi...

In C++, how to initialize static member of a private class declared inside a Singleton template ?

Ok, I should simply tell that I want to make a base Singleton class that I can inherit from, and the way I want to achieve that is by a template. In order to avoid memory leaks, I do not use directly a pointer to the instance, but a private class that will handle deleting the pointer. Here is my actual code (not working) : template <t...

DirectShow BaseClasses - a video renderer class with video and input pin

Hello I couldn't find a suitable renderer class in BaseClasses that has 2 input pins - one for video and one for audio. Can anybody recommend/provide some code? Regards Dominik ...

How to dynamically set your apps' Base priority to 31?

Hi! I have the following problem - I want to set my C++ application's Base priority to 31 if that is possible or at least set its current priority to 31. So I need a simple example like set priority to 31; for (i=0;i<100000;++i) { printf("hello world"); } set priority to 8 or keep 31 if possible ...

Win32 C/C++ - Detecting if IPv6 is installed

Is there a way to detect if the IPv6 protocol is installed without looping through all available IP addresses and checking for IPv6 addresses? I can't find anything on msdn. ...

I have lots of questions about c++ that are really confusing me

I started learning c++ about 3 weeks ago after 2 years of java. It seems so different but im getting there. my lecturer is a lovely guy but any time i ask a question as to why something is that way or this way. he just responds "because it is". Theres lots of comments in the code below with a few random questions, but the main problem ...

MSBuild: Custom.After.Microsoft.Common.targets for native C++ projects in VS2010

I've read about the use of "Custom.Before.Microsoft.Common.targets" and "Custom.After.Microsoft.Common.targets" in order to execute a custom target before/after every project build and I would like to use this technique in order to change version info while building on our TeamCity build server. The problem is that although it works fo...

In Qt (4.6), is it ok to call slots directly?

I found myself in the need of having to call a slot directly. I think it's perfectly fine doing it as long as it makes sense in your design. What do you think? Thanks ...

C++ network programing in linux: Server Questions

I am learning how to network program using c/c++ and I have created a server(TCP) that is suppose to respond in specific ways to messages from a client in order to do this I created a class that the server class passes the message to and returns a string to report back to the client. Here is my problem sometimes it reports the correct s...

Using MinGW built dll in a Visual Studio 2010 C++ project

Hi, I have build a dll and now I want to use this dll in a Microsoft Visual Studio project. g++ -O0 -Wall -c -fmessage-length=0 -osrc\MyLib.o ..\src\MyLib.cpp g++ -shared -Wl,--out-implib=MyLib.lib -Wl,--output-def=MyLib.def -oMyLib.dll src\MyLib.o -lwsock32 The dll works fine when I use it in a "gcc project". I have tried different ...

why is concurrent_queue non-blocking?

In the concurrency runtime introduced in VS2010, there is a concurrent_queue class. It has a non blocking try_pop() function. Similar in Intel Thread Building Blocks (TBB), the blocking pop() call was removed when going from version 2.1 to 2.2. I wonder what the problem is with a blocking call. Why was it removed from TBB? And why is th...

cannot convert parameter 1 from 'char' to 'LPCWSTR'

hi i keep getting this error: cannot convert parameter 1 from 'char' to 'LPCWSTR' int main(int argc, char argv[]) { // open port for I/O HANDLE h = CreateFile(argv[1],GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,NULL); if(h == INVALID_HANDLE_VALUE) { PrintError("E012_Failed to open port"); can someone help? ...

trouble with output directory for OpenCV VideoWriters.

Hi, I'm a math undergrad and have little programming experience. I'm interested in computer vision however. Tried to follow the Learning OpenCV book but its slightly outdated. How do i save the resulting video file in my linux home directory? for eg "/home/user/..", thanks in advance, this is my first post and i know i won't be disappoin...

Does C++0x for loop allow new or better optimizations?

In C++0x we can now do : void dosomething( std::vector<Thing>& things ) { for( Thing& thing : things ) { dofoo( thing ); wiizzz( thing ); tadaa( thing ); } } I know that the addition and use of lambda is syntactic sugar but it provide interesting optimization opportunities. What about the for loop...

Export part of the namespace of a class

I have a class that includes an enum: class appearance{ // ... stuff ... enum color {BLUE, RED, GREEN}; }; I would like to attach part of the namespace (with using) so that I can refer to the value of the BLUE simply as BLUE, rather than appearance::BLUE. At the same time, I would like to keep the enum within the class{}, since I ...

cvblob compile error in Visual C++ 6.0

Hi all! I'm using Microsoft Visual C++ 6.0 and Microsoft Visual Studio 2008 to develop an academic computer vision project. In this project i need to use OpenCV 1.1 (http://opencv.willowgarage.com/) and CvBlob (http://code.google.com/p/cvblob/). I tried to compile this project with Microsoft Visual Studio 2008 and it compiles without...

Linker for Clang?

Which linker do I use for clang? If I use clang or ld as a linker, I get massive amounts of errors as if I didn't link with the standard library. g++ $(OBJS) -o $(BINDIR)/obtap It seems I have to use g++ in order to link my clang objects. ...