The program is as following:
#include <iostream>
#include <boost/numeric/mtl/mtl.hpp>
using namespace mtl;
int main(int argc, char* argv[])
{
dense_vector<double> a(5,1.0);
dense_vector<double> b(5,2.0);
a * trans(b);
}
I want to calculate a * trans(b), but there is a compling error :C2893.
Will someone help me? Thanks a lot!
...
Hello, I am seeking to improve my C++ skills by writing a sample software renderer. It takes objects consisting of points in a 3d space and maps them to a 2d viewport and draws circles of varying size for each point in view. Which is better:
class World{
vector<ObjectBaseClass> object_list;
public:
void generate(){
objec...
I would like to 'shrink-to-fit' an std::vector, to reduce its capacity to its exact size, so that additional memory is freed. The standard trick seems to be the one described here:
template< typename T, class Allocator >
void shrink_capacity(std::vector<T,Allocator>& v)
{
std::vector<T,Allocator>(v.begin(),v.end()).swap(v);
}
The w...
In MSVC++ I have a vector.
Whenever you go out of bounds of the vector (in debug mode, launched as "Start Debugging"), when you step out of bounds of the vector the program halts with a dialog box:
Microsoft Visual C++ Debug Library
====
Debug Assertion Failed!
Expression: Vector subscript out of range
Abort | Retry | Ignore
So w...
Hi there
I am pretty new to XNA & game dev and am stuck at ball reflection. My ball is reflecting once it hits the bat, but only in one angle, no matter which angle the bat is at.
Here's the code:
if (BallRect.Intersects(BatRect))
{
Vector2 NormBallVelocity = Ball.velocity;
NormBallVelocity.Normalize();
Norm...
Often, it is more efficient to use a sorted std::vector instead of a std::set. Does anyone know a library class sorted_vector, which basically has a similar interface to std::set, but inserts elements into the sorted vector (so that there are no duplicates), uses binary search to find elements, etc.?
I know it's not hard to write, but p...
I'm trying to calculate distance between 2 points.
The 2 points I stored in a vector in c++: (0,0) and (1,1).
I'm supposed to get results as
0
1.4
1.4
0
but the actual result that I got is
0
1
-1
0
I think there's something wrong with the way I use iterator in vector.
Could somebody help? I posted the code below.
typedef struct po...
Hi,
I would like to populate an 2 dimensional array, from a vector.
I think the best way to explain myself is to put some examples (with a array of [3,5] length).
When vector is: [1, 0]
[
[4, 3, 2, 1, 0],
[4, 3, 2, 1, 0],
[4, 3, 2, 1, 0]
]
When vector is: [-1, 0]
[
[0, 1, 2, 3, 4],
[0, 1, 2, 3, 4],
[0, 1, 2, 3, 4]
]
...
I'm working on a game that has many elements on stage, so I'm looking to optimize my loops. I know that Vector is faster than looping an array, but I'm also in some cases using:
while (i < numChildren)
getChildAt(i)
...to update sprites.
My question is when I use getChildAt, is that accessing an Array or Vector or linked list or...
I want to sort a vector using std::sort, but my sort method is a static method of a class, and I want to call std::sort outside it, but it seems to be trouble doing it this way.
On the class:
static int CompareIt(void *sol1, void *sol2) { ... }
std::sort call:
sort(distanceList.at(q).begin(),
distanceList.at(q).end(),
&...
I have a class header file called Grid.h that contains the following 2 private data object:
vector<int> column;
vector<vector<int>> row;
And a public method whose prototype in Grid.h is such:
int getElement (unsigned int& col, unsigned int& row);
The definition of above mentioned function is defined as such in Grid.cpp:
int getEle...
Basically I have a proof-of-concept application that is a digital recipe book. Each Recipe is an object and each object has, among other fields, a Vector containing arrays. The Vector is the list of all ingredients in the Recipe while each ingredient has an array showing the name of the ingredient, the amount, and the unit for that amo...
IDE - Visual Studio 2008, Visual C++
I have a custom class Class1 with a copy constructor to it.
I also have a vector
Data is inserted using the following code
Class1* objClass1;
vector<Class1> vClass1;
for(int i=0;i<1000;i++) {
objClass1 = new Class1();
vClass1.push_back(*objClass1);
delete objClass1;
}
Now...
Hello folks,
let's say we have a class
class MyClass {
vector<vector<int > > myMatrice;
public :
MyClass(vector<vector<int > > &);
}
MyClass::MyClass(vector<vector<int > > & m) {
myMatrice = m;
}
During the instanciation of MyClass, I pass a big vector < vector < int > > and I find that the object is actually copied and not ...
Hello folks,
I have a vector< vector< vector< int>>> and I would like to extract from it a vector< vector< int>> to process it individually.
The problem is that when I write :
myMatrix = myCube[anIndex];
the matrix is copied but I only want a reference in order to save memory.
Can you please help me out ?
Thanks a lot!
...
Sometimes it is useful to use the starting address of an std::vector and temporarily treat that address as the address of a regularly allocated buffer.
For instance replace this:
char* buf = new char[size];
fillTheBuffer(buf, size);
useTheBuffer(buf, size);
delete[] buf;
With This:
vector<char> buf(size);
fillTheBuffer(&buf[0],...
I would like to manipulate matrices (full or sparse) efficiently with haskell's vector library.
Here is a matrix type
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector as V
data Link a = Full (V.Vector (U.Vector a))
| Sparse (V.Vector (U.Vector (Int,a)))
type Vector a = U.Vector a
As you can see, the matrix...
Hey, I've written a function to copy any variable type into a byte vector, however whenever I insert something it gets inserted in reverse.
Here's the code.
template <class Type>
void Packet::copyToByte(Type input, vector<uint8_t>&output)
{
copy((uint8_t*) &input, ((uint8_t*) &input) + sizeof(Type), back_inserter(output));
}
Now ...
I've got a two vectors in class A that contain other class objects B and C. I know exactly how many elements these vectors are supposed to hold at maximum. In the initializer list of class A's constructor, I initialize these vectors to their max sizes (constants).
If I understand this correctly, I now have a vector of objects of class ...
Hello,
I created a struct to hold some data and then declared a vector to hold that struct.
But when I do a push_back I get damn segfault and I have no idea why!
My struct is defines as:
typedef struct Group
{
int codigo;
string name;
int deleted;
int printers;
int subpage;
/*included this when it started seg...