c++

How to return a copy of the data in C++

I am trying to return a new copy of the data in a C++ Template class. The following code is getting this error: invalid conversion from ‘int*’ to ‘int’. If I remove the new T then I am not returning a copy of the data but a pointer to it. template<class T> T OrderedList<T>::get( int k ) { Node<T>* n = list; for( int i = ...

API for Asus 1005pe control backlight programmably?

I'm using VS2008, my OS is Win7. I tried WinAPI IOCTL_VIDEO_QUERY_SUPPORTED_BRIGHTNESS on my netbook. I can retrive a correct the LCD handle, but DeviceIoControl returns 0. I haven't found any APIs for GMA 3150 either. ...

Is this a good code (came across while reading code of a colleague)

File a.hpp: class a; typedef boost::shared_ptr<a> aPtr class a{ public: static aPtr CreateImp(); virtual void Foo() = 0 ; .... }; File aImp.hpp: class aImp : public a{ virtual void Foo(); }; File aImp.cpp: aPtr a::CreateImp() { return aPtr(new aImp()); } void aImp::Foo(){} The client must use CreateImp t...

Some questions about Vector in STL

I have some questions about vector in STL to clarify..... Where are the objects in vector allocated? heap? does vector have boundary check? If the index out of the boundary, what error will happen? Why array is faster than vector? Is there any case in which vector is not applicable but array is a must? ...

OpenGL true coordinates and glutTimerFunc() problem C++

HI I am starting to learn openGl for C++.but at stating point I stucked. I have 2 question that is the coordinates for drawing some objects? I mean where is X, Y and Z? Second one I am making tutorial from some sites. and I am trying to animate my triangle.In tutorial it works but on my computer not.I Also downloaded source codes b...

why no += operator for vectors in stl

I am curious? What high fundu logic goes behind not implementing: result+=vector1; where both result and vector1 are stl vectors. Note: i know how to implement that bit, but i need to know what logic, the sages who designed STL were using when they chose not to implement this feature? ...

cstdio,cstring,cmath ... recommended in c++?

Hi, Is it recommended to use cstdio,cstring,cmath in c++? I was writing a program that needed pow , strlen and sprintf ... for that the only way I could do it was to include these 3 headers. Is there a better C++ way to do it? Thanks ...

Find which numbers appears most in a vector

I have some numbers stored in a vector . I want to find which number appears most in the vector. Is there any easy/fast algorithm (STL or whatever) that does this ? ...

GCC emits extra code for boost::shared_ptr dereference

I have the following code: #include <boost/shared_ptr.hpp> struct Foo { int a; }; static int A; void func_shared(const boost::shared_ptr<Foo> &foo) { A = foo->a; } void func_raw(Foo * const foo) { A = foo->a; } I thought the compiler would create identical code, but for shared_ptr version an extra seemingly redundant instru...

What's the best way to resolve a filepath?

Hello everyone :) I've got a series of filepaths that look something like this: C:\Windows\System32\svchost.exe -k LocalSystemNetworkRestricted C:\Windows\System32\svchost C:\Program Files (x86)\Common Files\Steam\SteamService.exe /RunAsService "C:\Program Files (x86)\Common Files\Steam\SteamService.exe" /RunAsService and I need to ...

Why is casting Derived** to Base*const* forbidden ?

After reading this question, i saw the answer by Naveen containing a link to this page, which basically says, that casting from Derived** to Base** is forbidden since could change a pointer to an pointer to a Derived1 object point to a pointer to a Derived2 object (like: *derived1PtrPtr=derived2Ptr). OK, i understand this is evil ... B...

Static Function Help C++

I can't get past this issue I am having. Here's a simple example: class x { public: void function(void); private: static void function2(void); }; void x::function(void) { x::function2(void); } static void function2(void) { //something } I get errors in which complain about function2 being private. If I make it...

What does template<class key, class type> mean before a method in C++?

Hi, I have got this code and I am trying to understand the convention followed, all the method defined in the .cpp file have template<class KeyType, class DataType> written before them. What does that mean? Example: //Constructor template<class key, class type> MyOperation<key, type>::MyOperation() { //method implementation } //A m...

Differing paths for lua script and app

My problem is that I'm having trouble specifying paths for Lua to look in. For example, in my script I have a require("someScript") line that works perfectly (it is able to use functions from someScript when the script is run standalone. However, when I run my app, the script fails. I believe this is because Lua is looking in a locati...

Best Practice - Validating Input In Simple GUI Application?

I'm writing a GUI app with wxwidgets in C++ for one of my programming classes. We have to validate input and throw custom exceptions if it doesn't meet certain conditions. My question is, what is best practice when it comes to this? Should I write a seperate function that checks for errors, and have my event handler's call that function?...

How do I trap the ENTER key in WM 6.1 using C++

Hi,Our barcode scanner application is written in C++ eMbedded V 4.00 and works well on the Motorola MC50 WM5 where the ENTER key is interpreted as an IDOK. We are moving the app to the MC55 with WM6.1 and the ENTER key does not translate to an IDOK. I'm of the impression we will have to programatically trap the key entry (or the value ...

What would be the safest way to store objects of classes derived from a common interface in a common container?

I'd like to manage a bunch of objects of classes derived from a shared interface class in a common container. To illustrate the problem, let's say I'm building a game which will contain different actors. Let's call the interface IActor and derive Enemy and Civilian from it. Now, the idea is to have my game main loop be able to do thi...

implementing ioctl() commands in FreeBSD

I am adding some code to an existing FreeBSD device driver and I am trying to pass a char* from user space to the driver. I've implemented a custom ioctl() command using the _IOW macro like so: #define TIBLOOMFILTER _IOW(0,253,char*) My call looks something like this: int file_desc = open("/dev/ti0", O_RDWR); ioctl(file_desc, TIBLOOMF...

How To Get System Folder Path(C:\Windows C:\Program Files) in Windows using C++?

I am programming in c++ MFC, I want to get "C:\windows" "c:\program files" folder path. Sometimes user may setup windows in other folder such as c:\windows0. Is there any API to get absolute path of the windows and program files path? Many thanks! ...

Setting minimum number of decimal places for std::ostream precision

Hi, Is there a way to set the "minimum" number of decimal places that a std::ostream will output? For example, say I have two unknown double variables that I want to print (values added here for the sake of illustration): double a = 0; double b = 0.123456789; I can set my maximum decimal precision so that I output b exactly std::c...