Search Results

Search found 2746 results on 110 pages for 'vector algebra'.

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

  • 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

  • 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

  • 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

  • Vector [] vs copying

    - by sak
    What is faster and/or generally better? vector<myType> myVec; int i; myType current; for( i = 0; i < 1000000; i ++ ) { current = myVec[ i ]; doSomethingWith( current ); doAlotMoreWith( current ); messAroundWith( current ); checkSomeValuesOf( current ); } or vector<myType> myVec; int i; for( i = 0; i < 1000000; i ++ ) { doSomethingWith( myVec[ i ] ); doAlotMoreWith( myVec[ i ] ); messAroundWith( myVec[ i ] ); checkSomeValuesOf( myVec[ i ] ); } I'm currently using the first solution. There are really millions of calls per second and every single bit comparison/move is performance-problematic.

    Read the article

  • binary_search not working for a vector<string>

    - by VaioIsBorn
    #include <iostream> #include <string> #include <vector> #include <algorithm> using namespace std; int main(void) { string temp; vector<string> encrypt, decrypt; int i,n, co=0; cin >> n; for(i=0;i<n;i++) { cin >> temp; encrypt.push_back(temp); } for(i=0;i<n;i++) { cin >> temp; decrypt.push_back(temp); } for(i=0;i<n;i++) { temp = encrypt[i]; if((binary_search(decrypt.begin(), decrypt.end(), temp)) == true) ++co; } cout << co << endl; return 0; } It reads two equal lists of strings and should print out how many of the words in the first list are also found in the second list, simple. Not giving me the expexted results and i think the problem is in binary_search. Can you tell me why ?

    Read the article

  • C++ Array vs vector

    - by blue_river
    when using C++ vector, time spent is 718 milliseconds, while when I use Array, time is almost 0 milliseconds. Why so much performance difference? int _tmain(int argc, _TCHAR* argv[]) { const int size = 10000; clock_t start, end; start = clock(); vector<int> v(size*size); for(int i = 0; i < size; i++) { for(int j = 0; j < size; j++) { v[i*size+j] = 1; } } end = clock(); cout<< (end - start) <<" milliseconds."<<endl; // 718 milliseconds int f = 0; start = clock(); int arr[size*size]; for(int i = 0; i < size; i++) { for(int j = 0; j < size; j++) { arr[i*size+j] = 1; } } end = clock(); cout<< ( end - start) <<" milliseconds."<<endl; // 0 milliseconds return 0; }

    Read the article

  • C++: Vector of objects vs. vector of pointers to new objects?

    - by metamemetics
    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(){ object_list.clear(); object_list.push_back(DerivedClass1()); object_list.push_back(DerivedClass2()); or... class World{ vector<ObjectBaseClass*> object_list; public: void generate(){ object_list.clear(); object_list.push_back(new DerivedClass1()); object_list.push_back(new DerivedClass2()); ?? Would be using pointers in the 2nd example to create new objects defeat the point of using vectors, because vectors automatically call the DerivedClass destructors in the first example but not in the 2nd? Are pointers to new objects necessary when using vectors because they handle memory management themselves as long as you use their access methods? Now let's say I have another method in world: void drawfrom(Viewport& view){ for (unsigned int i=0;i<object_list.size();++i){ object_list.at(i).draw(view); } } When called this will run the draw method for every object in the world list. Let's say I want derived classes to be able to have their own versions of draw(). Would the list need to be of pointers then in order to use the method selector (-) ?

    Read the article

  • Are vector assignments copied by value or by reference in Google's Go language?

    - by Brian T Hannan
    In the following code, I create one peg puzzle then do a move on it which adds a move to its movesAlreadyDone vector. Then I create another peg puzzle then do a move on it which adds a move to its movesAlreadyDone vector. When I print out the values in that vector for the second one, it has the move in it from the first one along with the move from the second one. Can anyone tell me why it seems to be assigning by reference and not value? Are vector assignments copied by value or by reference in Google's Go language? package main import "fmt" import "container/vector" type Move struct { x0, y0, x1, y1 int } type PegPuzzle struct { movesAlreadyDone * vector.Vector; } func (p *PegPuzzle) InitPegPuzzle(){ p.movesAlreadyDone = vector.New(0); } func NewChildPegPuzzle(parent *PegPuzzle) *PegPuzzle{ retVal := new(PegPuzzle); retVal.movesAlreadyDone = parent.movesAlreadyDone; return retVal } func (p *PegPuzzle) doMove(move Move){ p.movesAlreadyDone.Push(move); } func (p *PegPuzzle) printPuzzleInfo(){ fmt.Printf("-----------START----------------------\n"); fmt.Printf("moves already done: %v\n", p.movesAlreadyDone); fmt.Printf("------------END-----------------------\n"); } func main() { p := new(PegPuzzle); cp1 := new(PegPuzzle); cp2 := new(PegPuzzle); p.InitPegPuzzle(); cp1 = NewChildPegPuzzle(p); cp1.doMove(Move{1,1,2,3}); cp1.printPuzzleInfo(); cp2 = NewChildPegPuzzle(p); cp2.doMove(Move{3,2,5,1}); cp2.printPuzzleInfo(); } Any help will be greatly appreciated. Thanks!

    Read the article

  • How can I partition a vector?

    - by Karsten W.
    How can I build a function slice(x, n=2) which would return a list of vectors where each vector except maybe the last has size n, i.e. slice(letters, 10) would return list(c("a", "b", "c", "d", "e", "f", "g", "h", "i", "j"), c("k", "l", "m", "n", "o", "p", "q", "r", "s", "t"), c("u", "v", "w", "x", "y", "z")) ?

    Read the article

  • vector drawing canvas in GWT

    - by Limbic System
    Are there are decent implementations of a vector graphics canvas in GWT? I would like to be draw arbitrary shapes and have them react to user input (mouse in/out/click/etc). There are wrappers for the HTML canvas, but that feature is not supported in older browsers (read: IE).

    Read the article

  • Vector graphics on iPhone

    - by burki
    Hello! How you can use EPS files within your UIView. What do I have to do to display for example a EPS on the iPhone's screen? Do I need to convert it first to a PDF (if yes, how?)? Or are there any other way to bring vector graphics onto the iPhone? That would be very nice. Thanks.

    Read the article

  • C++ Map of Vector of Structs?

    - by garsh0p
    So here's a snippet of my code: struct dv_nexthop_cost_pair { unsigned short nexthop; unsigned int cost; }; map<unsigned short, vector<struct dv_nexthop_cost_pair> > dv; I'm getting the following compiler error: error: ISO C++ forbids declaration of `map' with no type What's the proper way to declare this?

    Read the article

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