c++

new/delete "override" vs. "overload"

I always thought... overriding means reimplementing a function (same signature) in a base class whereas overloading means implementing a function with same name but different signature ... and got confused because sometimes people just don't care about the difference. Concerning new/delete: Are they overloaded or overridden? An ide...

How to start a DVD playback on Windows using the default playback software?

Does anybody know how to initiate a DVD playback using a known drive letter from out of a C++ program. For what's worth: I simply search for the windows explorer's play function which is located in the context menu when right-clicking a DVD drive... Thx in advance, Axel ...

Why do I get "error C2006: '#include' : expected a filename, found 'identifier' " ?

Hello! My source code in Visual C++ Express 2008 is as follows : #include “stdafx.h” #include <iostream> int _tmain(int argc, _TCHAR* argv[]) { std::cout << “Hello world!\n”; return 0; } I'm using the book, Visual C++ 2008,by Ivor Horton .These are the errors that I'm encountering.How do I get rid of the errors ? 1>e:\my documen...

Assign derived class to base class

Is it safe to do the following or is it undefined behaviour: class Base { private: int a; }; class Derived : public Base { private: int b; }; Base x; Derived y; x = y; // safe? Do the extra bits in derived classes just get sliced off? ...

A way to read data out of a file at compile time to put it somewhere in application image files to initialize an array.

considering visual C++ compiler, Lets say I've got a file with whatever extension and it contains 100 bytes of data which are exactly the data that I want to initialize an array of char data type with a length of 100 characters with, Now apparently one way is to read those data out of file by using I/O file classes or APIs at run-time bu...

What is the correct way to implement the comparison for a base class?

I have a base class class Animal with pure virtual functions, and a set of derived classes class Monkey : public Animal class Snake : public Animal I want to implement a comparison operation so that, if I encounter two pointers to Animals in my code Animal* animal1 Animal* animal2 I can compare them to each other. The compar...

How to use static members as template arguments?

I have the following code structure: myClass.h class myClass { public: void DoSomething(void); }; myClass.cpp #include myClass.h static const unsigned length = 5; static myArray<float, length> arrayX; void myClass::DoSomething(void) { // does something using length and array X } Now I want to convert the static variable ...

interesting situation in c++

#include <iostream> #include <stdlib.h> using namespace std; int main(int argc, char* argv[]) { std:: cout<<"hello world"; std::cout<<"i am surprise<"<<std::endl; return (EXIT_SUCCESS); } It is very strange because I am using netbeans in Ubuntu 10.04 and run this code. What happens here really makes me surprised; every line o...

How to get Xlib code work in eclipse for C++ ubuntu

I have some code with the following headers for Xlib but don't know what to do to make it work...I can't find these headers. #include <X11/Xlib.h> #include <X11/Xutil.h> #include <X11/Xos.h> #include <X11/Xatom.h> Sorry new to this.. Okay so now I can view the headers in the foldrrs in my eclipse IDE. and i get the following errors.Th...

includes inside a namespace

Hi All Is the following approach correct? Well i get a compilation error. a.hpp is #include <iostream> class a { public: void classa_f(); }; a.cpp is #include "a.hpp" void a::classa_f() { std::cout<< "a::classa_f\n"; } main.cpp #include <iostream> namespace myname { #include "a.hpp" } int main () { myname::a ...

error in this code

i have following code #include <iostream> #include <set> #include <string> using namespace std; template<class Container> void print(const Container &c) { Container::const_iterator itr; for (itr=c.begin();itr!=c.end();itr++){ cout<<*itr<< '\n'; } } int main(){ set<string,greater<string>>s; s.insert("georgia"); ...

How to correct RGB color taken with camera ?

Hi everyone, I had this question in my mind lately: I have taken a photo of a picture in my computer's display using my phone's camera (2MP) then transferred the picture to my computer. What i have noticed is that the individual pixel (RGB) values of the photographed image are different from the original picture (which is obvious !) but...

Get camera inside my skybox

So I am working on a homework assignment and I have managed to create my skybox and it looks correct, the only problem is that my camera is outside the skybox. I tried the command gluLookAt thinking maybe that would focus me into the box, but it didn't work. Here's the code that I have now. If anyone could let me know what I'm doing...

flycaputer2 link error

Hi, I have some simple code using Point Gray's FlyCapture libraries: #include <iostream> #include "FlyCapture2.h" using namespace std; int main(){ cout << "Hello World!"; FlyCapture2::BusManager m; return 0; } The above code gives these link error at compile time: 1>------ Build started: Project: CJMVideo, Configuratio...

"Invalid conversion" error with conditional operator

I'm getting compile error in this line: cout << (MenuItems[i].Checkbox ? (MenuItems[i].Value ? txt::mn_yes : txt::mn_no) : MenuItems[i].Value) Error: menu.cpp|68|error: invalid conversion from 'int' to 'const char*' menu.cpp|68|error: initializing argument 1 of 'std::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT*...

Macro detect KDE or GNOME in qt4

Hi, I have a problem to detect when used in GNOME or KDE operating system that runs the application. The program I am doing QT4, and I have trouble feeling of look- in the systray, so I pass it to KDE, but which is not macro to do so. PD: I use KDE and C / C. I search in web and I see this: http://stackoverflow.com/questions/963611/creat...

C++ Serial Blocking Read

I'm trying to create a C++ serial port class for a project that i'm working on. Unfortunately I'm stuck. I need the user to be able to specify if the port read function is blocking or non-blocking. So when the user creates a port object they specify a flags variable. If flags is set then the read should return -1 if there is no data at t...

Template function specialization for specific interface

I have the following piece of code: class ICookable { public: virtual void CookMe () = 0; virtual ~ICookable () {}; }; class Egg : public ICookable { public: virtual void CookMe () {cout << "Egg cooked!" << endl;} }; template <class T> void Cook (T&) { cout << "Item Uncookable!" << endl; } template <> void Cook (ICook...

place a value in the sorted position immediately

Hello, I have a question for a c++ lab assignment I have. The task is to implement some function for adding values, remove values from an array and so on. I have done most of it now, however I have some problem with the insert function. The assignment requires me to insert float values to this array without using any algorithm to sort it...

Boost threads: is it possible to limit the run time of a thread before moving to another thread.

I have a program with a main thread and a diagnostics thread. The main thread is basically a while(1) loop that performs various tasks. One of these tasks is to provide a diagnostics engine with information about the system and then check back later (i.e. in the next loop) to see if there are any problems that should be dealt with. An...