Search Results

Search found 2659 results on 107 pages for 'vector drawings'.

Page 8/107 | < Previous Page | 4 5 6 7 8 9 10 11 12 13 14 15  | Next Page >

  • const pod and std::vector

    - by Baz
    To get this code to compile: std::vector<Foo> factory() { std::vector<Foo> data; return data; } I have to define my POD like this: struct Foo { const int i; const int j; Foo(const int _i, const int _j): i(_i), j(_j) {} Foo(Foo& foo): i(foo.i), j(foo.j){} Foo operator=(Foo& foo) { Foo f(foo.i, foo.j); return f; } }; Is this the correct approach for defining a pod where I'm not interested in changing the pod members after creation? Why am I forced to define a copy constructor and overload the assignment operator? Is this compatible for different platform implementations of std::vector? Is it wrong in your opinion to have const PODS like this? Should I just leave them as non-const?

    Read the article

  • Moving a point along a vector

    - by Chris
    Hello- I have a point defined by x,y and a vector defined by heading, speed. I am attempting to move the point x,y along this vector, at a distance of 'speed'. Below is the code I am currently using: self.x += self.speed * cos(self.heading); self.y += self.speed * sin(self.heading); Heading can be any angle in a full circle - 0 to 2p (0-360 degrees). The problem is the above code: Only moves along the x or y axis when angle is 0-270 for example, when the avatar is facing the top-right corner (45 degrees relative), it moves straight up. Does not move at all when angle is 270-360 heading, speed, X and Y are all doubles, and heading is reported by the user touching a direction-pad in the lower corner. I know the heading is correct because the avatar rotates to the correct direction, it is just the actual movement I am having problems with. Thanks for any help - Chris

    Read the article

  • Adding an Object to Vector loses Reference using Java?

    - by thechiman
    I have a Vector that holds a number of objects. My code uses a loop to add objects to the Vector depending on certain conditions. My question is, when I add the object to the Vector, is the original object reference added to the vector or does the Vector make a new instance of the object and adds that? For example, in the following code: private Vector numbersToCalculate; StringBuffer temp = new StringBuffer(); while(currentBuffer.length() > i) { //Some other code numbersToCalculate.add(temp); temp.setLength(0); //resets the temp StringBuffer } What I'm doing is adding the "temp" StringBuffer to the numbersToCalculate Vector. Should I be creating a new StringBuffer within the loop and adding that or will this code work? Thanks for the help! Eric

    Read the article

  • Simple vector program error

    - by Codeguru
    Hi iam new to c++ and iam trying out this vector program and i am getting the following error: error: conversion from test*' to non-scalar typetest' requested| Here is the code include include include include using namespace std; class test{ string s; vector <string> v; public: void read(){ ifstream in ("c://test.txt"); while(getline(in,s)) { v.push_back(s); } for(int i=0;i<v.size();i++) { cout<<v[i]<<"\n"; } } }; int main() { cout<<"Opening the file to read and displaying on the screen"< }

    Read the article

  • Function that copies into byte vector reverses values

    - by xeross
    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 whenever I add for example a uint16_t with the value 0x2f1f it gets inserted as 1f 2f instead of the expected 2f 1f. What am I doing wrong here ? Regards, Xeross

    Read the article

  • Declaring STL Data Structures such as Vector in the .h

    - by sc_ray
    I am trying to declare a private Data Structure such as the Vector in my C++ header file which I want to eventually use within the method implementation of my .cpp. An example would be my header "SomeClass.h" where I have: class SomeClass { private: Vector<T> myVector; public: void AddTtoMyVector(T add); } And in my .cpp which is "SomeClass.cpp", I have the following: #include "SomeClass.h" SomeClass::AddTtoMyVector(T add) { myVector.Push_back(add); } Would the syntax here work? Or is there a different way of declaring and populating such structures?

    Read the article

  • How to initialise a STL vector/list with a class without invoking the copy constructor

    - by Warpspace
    I have a C++ program that uses a std::list containing instances of a class. If I call e.g. myList.push_back(MyClass(variable)); it goes through the process of creating a temporary variable, and then immediately copies it to the vector, and afterwards deletes the temporary variable. This is not nearly as efficient as I want, and sucks when you need a deep copy. I would love to have the constructor of my class new something and not have to implement a copy constructor just to allocate my memory for the second time and waste runtime. I'd also rather not have to immediately find the class instance from the vector/list and then manually allocate the memory (or do something horrible like allocate the memory in the copy constructor itself). Is there any way around this (I'm not using Visual Studio BTW)?

    Read the article

  • Capturing WPF Vector Information BEFORE it Renders to Screen

    - by user273722
    I'm trying to "capture" or record the vector display information of a WPF (maybe Silverlight) application and play it back. However, instead of capturing bitmaps of what is rendered, I would like to capture the vector information BEFORE it gets rendered so that I can play it back at different resolutions without loss of quality. Ideally, I'd like to do this without having to add assemblies into my app (but willing to do so if necessary). I've looked into the WPF rendering pipeline and cannot find an appropriate starting point (or, stated differently, I couldn't figure it out). Maybe the VisualTreeHelper class?

    Read the article

  • What is the need for normalizing a vector?

    - by Rashed Hassan
    Trying to understand vectors a bit more. What is the need for normalizing a vector? If I have a vector, N = (x, y, z) What do you actually get when you normalize it - I get the idea you have to divide x/|N| y/|N| & z/|N|. My question is, why do we do this thing, I mean what do we get out of this equation? What is the meaning or 'inside' purpose of doing this. A bit of a maths question, I apologize, but I am really not clear in this topic.

    Read the article

  • small string optimization for vector?

    - by BuschnicK
    I know several (all?) STL implementations implement a "small string" optimization where instead of storing the usual 3 pointers for begin, end and capacity a string will store the actual character data in the memory used for the pointers if sizeof(characters) <= sizeof(pointers). I am in a situation where I have lots of small vectors with an element size <= sizeof(pointer). I cannot use fixed size arrays, since the vectors need to be able to resize dynamically and may potentially grow quite large. However, the median (not mean) size of the vectors will only be 4-12 bytes. So a "small string" optimization adapted to vectors would be quite useful to me. Does such a thing exist? I'm thinking about rolling my own by simply brute force converting a vector to a string, i.e. providing a vector interface to a string. Good idea?

    Read the article

  • Using a class with const data members in a vector

    - by Max
    Given a class like this: class Foo { const int a; }; Is it possible to put that class in a vector? When I try, my compiler tells me it can't use the default assignment operator. I try to write my own, but googling around tells me that it's impossible to write an assignment operator for a class with const data members. One post I found said that "if you made [the data member] const that means you don't want assignment to happen in the first place." This makes sense. I've written a class with const data members, and I never intended on using assignment on it, but apparently I need assignment to put it in a vector. Is there a way around this that still preserves const-correctness?

    Read the article

  • Insert at specific location of a 2d vector

    - by Elgoog
    I have a 2d vector which represents a 2d grid; so grid[0][2] for example. I am needing to 'insert' -might not be the right word here. a vector at a specific location say grid[3][2] there will definitely be a grid[0][0] but when im needing to insert into grid[3][2] there may be nothing before it other than grid[0][0] and there needs to be the space in between for later on. Is there any way to do this? Thank you for your help. ps: I should note that the size of the vectors are not known (they will grow over time)

    Read the article

  • Vector of objects

    - by Paul
    I've got a abstract class class A { public: virtual void somefunction() = ; }; and some different classes that inherit this class: class Ab { public: void somefunction(); }; etc. I want to make a vector containing some objects of these classes (how many depends on input parameters) so I can access these easily later. However I'm a bit lost on how to do this. My best idea is vector<A> *objectsVector; Ab AbObject; objectsVector.push_back(AbObject); However this gives me a huge amout of errors from various .h files in /usr/include/c++ How should i solve this?

    Read the article

  • how to access child instances in a vector in c++

    - by tsubasa
    I have a parent class and child class (inherited from parent). In the child class, I have a member function named function_blah(); I used vector<parent*> A to store 5 parent instances, 3 child instances. So the total number of elements in the vector is 8. I can easily access to member functions of element A[0] to A[4], which are parent instances. But whenever I try to have access to member functions of element A[5] to A[7], the compiler complains that class parent has no member named 'function_blah' The way I access to elements is using index. e.x A[i] with i = 0..7. Is it correct? if not, how?

    Read the article

  • Looking for a mobile platform to view vector data and use it like a simple map

    - by Orchestrator
    I would like to develop or use an existing platform that will allow me to view custom vector data and use it as a map on mobile phones such as Android/IPhone (Maybe even WP7). I'm hoping that there's already a good infrastructure for what I need so I would not need to develop a whole infrastructure by myself. In Conclusion - Is there any existing platform that may answer my needs? If not, how would you guys suggest I should begin? How should I save my vector data? How could I read it? Should I view it with a graphics engine like OpenGL? Is there any chance this solution could be cross-platform? I know that it's possible since it was already done with apps like Waze. And it works the same on iOS and Android. Thanks!

    Read the article

  • C++ printf std::vector

    - by Sebtm
    How I can do something like this in C++: void my_print(format_string) { vector<string> data; //Fills vector printf(format_string, data); } my_print("%1$s - %2$s - %3$s"); my_print("%3$s - %2$s); I have not explained well before. The format string is entered by the application user. In C# this works: void my_print(format_string) { List<string> data = new List<string>(); //Fills list Console.WriteLine(format_string, data.ToArray); } my_print("{0} - {1} - {2}"); my_print("{2} - {1}");

    Read the article

  • Why can't I reserve 1,000,000,000 in my vector ?

    - by vipersnake005
    When I type in the foll. code, I get the output as 1073741823. #include <iostream> #include <vector> using namespace std; int main() { vector <int> v; cout<<v.max_size(); return 0; } However when I try to resize the vector to 1,000,000,000, by v.resize(1000000000); the program stops executing. How can I enable the program to allocate the required memory, when it seems that it should be able to? I am using MinGW in Windows 7. I have 2 GB RAM. Should it not be possible? In case it is not possible, can't I declare it as an array of integers and get away? BUt even that doesn't work. Another thing is that, suppose I would use a file(which can easily handle so much data ). How can I let it read and write and the same time. Using fstream file("file.txt', ios::out | ios::in ); doesn't create a file, in the first place. But supposing the file exists, I am unable to use to do reading and writing simultaneously. WHat I mean is this : Let the contents of the file be 111111 Then if I run : - #include <fstream> #include <iostream> using namespace std; int main() { fstream file("file.txt",ios:in|ios::out); char x; while( file>>x) { file<<'0'; } return 0; } Shouldn't the file's contents now be 101010 ? Read one character and then overwrite the next one with 0 ? Or incase the entire contents were read at once into some buffer, should there not be atleast one 0 in the file ? 1111110 ? But the contents remain unaltered. Please explain. Thank you.

    Read the article

  • C++ destructor issue with std::vector of class objects

    - by Nigel
    I am confused about how to use destructors when I have a std::vector of my class. So if I create a simple class as follows: class Test { private: int *big; public: Test () { big = new int[10000]; } ~Test () { delete [] big; } }; Then in my main function I do the following: Test tObj = Test(); vector<Test> tVec; tVec.push_back(tObj); I get a runtime crash in the destructor of Test when I go out of scope. Why is this and how can I safely free my memory?

    Read the article

  • Access violation C++ (Deleting items in a vector)

    - by Gio Borje
    I'm trying to remove non-matching results from a memory scanner I'm writing in C++ as practice. When the memory is initially scanned, all results are stored into the _results vector. Later, the _results are scanned again and should erase items that no longer match. The error: Unhandled exception at 0x004016f4 in .exe: 0xC0000005: Access violation reading location 0x0090c000. // Receives data DWORD buffer; for (vector<memblock>::iterator it = MemoryScanner::_results.begin(); it != MemoryScanner::_results.end(); ++it) { // Reads data from an area of memory into buffer ReadProcessMemory(MemoryScanner::_hProc, (LPVOID)(*it).address, &buffer, sizeof(buffer), NULL); if (value != buffer) { MemoryScanner::_results.erase(it); // where the program breaks } }

    Read the article

  • Evenly distribute range of specified values within a vector

    - by nofunsally
    I have a vector A and I want to populate it with values as evenly as possible. For example, if A is 1x30 and I want to use three values I would use a code like this below: % A = zeros(1,30); A([1:10])=0; A([11:20])=1; A([21:30])=2; This works, but seems a bit cumbersome to me. Is there a more elegant way to evenly (as possible) distribute a specified range of values within a vector? I am intent on keeping each of the values in "clumps." Thank you kindly in advance.

    Read the article

  • How does this circle collision detection math work?

    - by Griffin
    I'm going through the wildbunny blog to learn about collision detection. I'm confused about how the vectors he's talking about come into play. Here's the part that confuses me: p = ||A-B|| – (r1+r2) The two spheres are penetrating by distance p. We would also like the penetration vector so that we can correct the penetration once we discover it. This is the vector that moves both circles to the point where they just touch, correcting the penetration. Importantly it is not only just a vector that does this, it is the only vector which corrects the penetration by moving the minimum amount. This is important because we only want to correct the error, not introduce more by moving too much when we correct, or too little. N = (A-B) / ||A-B|| P = N*p Here we have calculated the normalised vector N between the two centres and the penetration vector P by multiplying our unit direction by the penetration distance. I understand that p is the distance by which the circles penetrate, but I don't get what exactly N and P are. It seems to me N is just the coordinates of the 3rd point of the right trianlge formed by point A and B (A-B) then being divided by the hypotenuse of that triangle or distance between A and B (||A-B||). What's the significance of this? Also, what is the penetration vector used for? It seems to me like a movement that one of the circles would perform to get un-penetrated.

    Read the article

  • Is DxScene the "WPF for Delphi"? Anyone used it?

    - by André Mussche
    I am playing with DxScene and VxScene: http://www.ksdev.com/dxscene/index.html It looks very nice and powerful: 3d accelerated vector graphics, cross plaform, nice effects, many 2d GUI controls (vector based), good scaling, transparency, rotating (x, y, z), 3d models, etc. Even with many effects, the CPU stays very low (0%)! http://www.ksdev.com/dxscene/snapshot/screen0.jpeg But can it be seen as a good WPF alternative for Delphi? And does anyone use it instead of normal Delphi VCL?

    Read the article

  • Performance of vector::size() : is it as fast as reading a variable?

    - by zoli2k
    I have do an extensive calculation on a big vector of integers. The vector size is not changed during the calculation. The size of the vector is frequently accessed by the code. What is faster in general: using the vector::size() function or using helper constant vectorSize storing the size of the vector? I know that compilers usually able to inline the size() function when setting the proper compiler flags, however, making a function inline is something that a compiler may do but can not be forced.

    Read the article

< Previous Page | 4 5 6 7 8 9 10 11 12 13 14 15  | Next Page >