c++

How can I check the network connection type using the Windows API?

How can I programmatically retrieve the current connection type (eg. LAN or Direct connection)? InternetGetConnectedState() isn't very reliable. For instance, I'm connected to a wireless network, but ConTypeRet is 18, which is INTERNET_CONNECTION_LAN & INTERNET_RAS_INSTALLED. Isn't there any way to make sure that ConTypeRet is either I...

C++ How do you set an array of pointers to null in an initialiser list like way?

I am aware you cannot use an initialiser list for an array. However I have heard of ways that you can set an array of pointers to NULL in a way that is similar to an initialiser list. I am not certain how this is done. I have heard that a pointer is set to NULL by default, though I do not know if this is guaranteed/ in the C++ standard...

How to read in a double from a file in c++

How do you read in a double from a file in C++? For ints I know you can use the getline() and then atoi, but I am not finding an array to double function. What is available for reading in doubles, or converting a char array to a double? ...

return value (not a reference) from the function, bound to a const reference in the calling function; how is its lifetime extended to the scope of the calling function ?

"If you return a value (not a reference) from the function, then bind it to a const reference in the calling function, its lifetime would be extended to the scope of the calling function." So: CASE A const BoundingBox Player::GetBoundingBox(void) { return BoundingBox( &GetBoundingSphere() ); } Returns a value of type const Boundi...

Is sizeof in C++ evaluated at compilation time or run time?

For example result of this code snippet depends on which machine: the compiler machine or the machine executable file works? sizeof(short int) ...

Get list of windows in taskbar on Windows 7?

Hi, how can I get a list of windows shown on the taskbar on Windows 7? I have tried EnumWindows, but I'm getting way more windows than those shown on the taskbar (800 vs 15). ...

What is the ISO C++ way to directly define a conversion function to reference to array?

According to the standard, a conversion function has a function-id operator conversion-type-id, which would look like, say, operator char(&)[4] I believe. But I cannot figure out where to put the function parameter list. gcc does not accept either of operator char(&())[4] or operator char(&)[4]() or anything I can think of. Now, gcc see...

template type's ctor arguments at instantiation time

template <typename T> class A { public: T t; void Do (void) { t.doSomething(); } }; In the above, how do I supply parameters to the constructor of 't' at the time of template instantiation?. Like, if I had: class P1 { public: P1 (int i, int a) {} }; class P2 { public: P2 (int a) {} }; I would like to use ...

No Matching Function Error for inserting into a list in c++

I am getting an error when I try to insert an item into a list (in C++). The error is that there is no matching function for call to the insert(). I also tried push_front() but got the same error. Here is the error message: main.cpp:38: error: no matching function for call to ‘std::list<Salesperson, std::allocator<Salesperson> >::ins...

C++ How fast is passing around objects?

Assuming we are running a compiled C++ binary: Is passing around an int (e.g. function to function, or writing it into variables) slower than passing around structs/class objects like the following? class myClass { int a; int b; char c; vector d; string e; } ...

Does anyone have good tips for using pc-lint?

What are some best practices for using pc-lint - how to wade thru the zillion options? I'm particularly interested in better ways to read/parse the output files. ...

C++ template nontype parameter arithmetic

hello I am trying to specialize template the following way: template<size_t _1,size_t _2> // workaround: bool consecutive = (_1 == _2 - 1)> struct integral_index_ {}; ... template<size_t _1> struct integral_index_<_1, _1 + 1> { // cannot do arithmetic? //struct integral_index_<_1, _2, true> { workaround }; however I get compiler mess...

Easy way to parse a url in C++ cross platform?

I need to parse a url to get the protocol host path and query in an application I am writing in c++. The application is intended to be cross platform. Im surprised I cant find anything that does this in boost or poco libraries. Is it somewhere obvious Im not looking? Any suggestions on appropriate open source libs? Or is this something I...

How to properly use references with variadic templates

I have something like the following code: template<typename T1, typename T2, typename T3, typename T4> void inc(T1& t1, T2& t2, T3& t3, T4& t4) { ++t1; ++t2; ++t3; ++t4; } template<typename T1, typename T2, typename T3> void inc(T1& t1, T2& t2, T3& t3) { ++t1; ++t2; ++t3; } template<typename T1, typename T2> void inc...

Returning object from function

I am really confused now on how and which method to use to return object from a function. I want some feedback on the solutions for the given requirements. Scenario A: The returned object is to be stored in a variable which need not be modified during its lifetime. Thus, const Foo SomeClass::GetFoo() { return Foo(); } invoked as: ...

C++ Class Access Specifier Verbosity

A "traditional" C++ class (just some random declarations) might resemble the following: class Foo { public: Foo(); explicit Foo(const std::string&); ~Foo(); enum FooState { Idle, Busy, Unknown }; FooState GetState() const; bool GetBar() const; void SetBaz(int); private: struct FooPartialImpl; void HelperFun...

What is the best way to make a schedule in MFC

I have a list of items that are each associated with a start and end time and date. What I want to do is, given a time and date range, display only the items that fall within that window, even partially. What I'm doing is creating a CListCtrl with all the items in it and the CListCtrl is sorted by start time by default. But given a ti...

Custom dropdown for CComboBox

I'm trying to create a custom dropdown for a derivative of CComboBox. The dropdown will be a calendar control plus some 'hotspots', e.g. So I figure the best way to achieve this is to have a simple CWnd-derived class which acts as the parent to the calendar control, and have it paint the hotspots itself. The window needs to be a pop...

close button only for some tabs in Qt

Hello, I am using Qt for an assignment I have for college, and I want to use QTabWidget to display a chat window much like Pidgin's. I want to make the "group chat" tab always open and impossible to close and the rest of the "private channel" tabs closable. QTabWidget's setTabsClosable(bool) is not helping ... any ideas? ty ...

c++ address string -> long

I got an adress example: 0x003533 , its a string but to use it i need it to be a LONG but i dont know how to do it :S has anybody a solution? so string: "0x003533" to long 0x003533 ?? ...