I currently have a std::vector which holds std::vector of double. I'd want to sort it by the second element of the double vectore. ex:
instead of sorting by MyVec[0] or myvec[1] I wat it to sort myVec[0] and myvec[1] based on myvec[0][1] myvec[1][1]. Basically sort by a contained value, not the objects in it.
so if myvec[0][1] is less t...
Possible Duplicate:
C++ - Arguments for Exceptions over Return Codes
While you are doing C++ programming, you have two choices of reporting an error. I suppose many teachers would suggest you throw an exception, which is derived from std::exception. Another way, which might be more "C" style, is to return a non-zero value, as ...
This is an example of my codes:
template <typename T> struct MyStruct {
T object;
}
template <typename T> class MyClass {
MyStruct<T>* structPool;
size_t structCount;
MyClass(size_t count) {
this->structCount = count;
this->structPool = new MyStruct<T>[count];
for( size_t i=0 ; i<count ; i++ ) ...
Possible Duplicate:
Storing third-party libraries in source control
I'm currently starting a project which is going to be developed on a few different computer and I'm keeping in sync with bzr. In the project I'm using a couple of 3rd party libraries, like SDL. In the past I've just pushed a copy of the compiled library to my ...
what's the alternative?
Should I write by myself?
...
I am new to C++ (just starting). I come from a Java background and I was trying out the following piece of code that would sum the numbers between 1 and 10 (inclusive) and then print out the sum:
/*
* File: main.cpp
* Author: omarestrella
*
* Created on June 7, 2010, 8:02 PM
*/
#include <cstdlib>
#include <iostream>
using name...
I've loaded a Wavefront .obj file and drawn it in immediate mode, and it works fine.
I'm now trying to draw the same model with a vertex buffer, but I have a question.
My model data is organized in the following structures:
struct Vert
{
double x;
double y;
double z;
};
struct Norm
{
double x;
double y;
double z;
};
struct ...
It is well known that cin is not typesafe (e.g. cin >> integer; and entering "fifty five" will cause it to flip out). I have seen many not-so-elegant ways to hand this, such as getlining a string and using sstream to convert it to a number, or looping with cin.fail() and clearing the stream and reentering it, etc. Is there any library or...
Recently, I have a utilities function of
// T2CA
#include "ATLCONV.H"
std::string Utils::CString2String(const CString& cString)
{
#if _MSC_VER > 1200
// Convert a TCHAR string to a LPCSTR
// construct a std::string using the LPCSTR input
CT2CA tmp(cString);
std::string strStd (tmp);
#else
// Deprecated in VC2008.
...
Hi there, I have function which takes in an parameter of a class called "Triple", and am returning the averge of 3 values of type float.
template <typename ElemT>
float average(Triple ElemT<float> &arg){
float pos1 = arg.getElem(1);
float pos2 = arg.getElem(2);
float pos3 = arg.getElem(3);
return ( (pos1+pos2+po3) /3 );...
hello.
Can you please explain me the difference between mechanism of the following:
int function();
template<class T>
void function2(T&);
void main() {
function2(function()); // compiler error, instantiated as int &
const int& v = function();
function2(v); // okay, instantiated as const int&
}
is my reasoning correct w...
i want to use GdipDrawString api in vc++ but i do'nt know which header file should be include
...
Unlike new and delete operators malloc does not call the constructor when an object is created. In that case how must we create an object so that the constructor will also be called.
...
I'm not afraid to admit that I'm somewhat of a C++ newbie, so this might seem like a silly question but....
I see DWORD used all over the place in code examples. When I look up what a DWORD truly means, its apparently just an unsigned int (0 to 4,294,967,295). So my question then is, why do we have DWORD? What does it give us that the i...
I'm not real hip on exactly what role(s) today's proxy servers can play and I'm learning so go easy on me :-) I have a client/server system I have written using a homegrown protocol and need to enhance the client side to negotiate its way out of a proxy environment.
I have an existing client and server system written in C and C++ for t...
Hello,
I got a C++ dll which has to be integrated in a C# project.
I think I found the correct way to do it, but calling the dll gives me this error:
System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
This is the function in the dll:
extern long FAR PAS...
At some places in my code, I print debug messages like this:
int ret = getLinkSpeed(device.getSysName(), linkSpeed);
if (ret < 0)
{
logDebug("Failed to obtain port speed for this device. Error: " + std::string(strerror(errno)));
}
From the documentation it is not entirely clear if strerror will return 0 under certain conditions (w...
While perusing the Qt source code I came across this gem:
template <class T> inline T qgraphicsitem_cast(const QGraphicsItem *item)
{
return int(static_cast<T>(0)->Type) == int(QGraphicsItem::Type)
|| (item && int(static_cast<T>(0)->Type) == item->type()) ? static_cast<T>(item) : 0;
}
Notice the static_cast<T>(0)->Type? I...
How can I convert a "YYYY/MM/DD" formatted date to a VARIANT type date and vice-versa in C++?
EDIT
VARIANT VT_DATE Type passed by VBA code into an automation COM written in c++
...
C++ and Java support return-type covariance when overriding methods.
Neither, however, support contra-variance in parameter types - instead, it translates to overloading (Java) or hiding (C++).
Why is that? It seems to me that there is no harm in allowing that. I can find one reason for it in Java - since it has the "choose-the-most-sp...