227 Archived Topics
Remove Filter If I make an array like this [code] GLubyte bufImage[100][100][3]; [/code] I can pass bufImage to a function and then get the values using: [code] r = bufImage[im_x][im_y][0]; g = bufImage[im_x][im_y][1]; b = bufImage[im_x][im_y][2]; [/code] However, if I don't know Width and Height at runtime, this does not work. I … | |
I've seen a few questions about this floating around here (mostly from me :) ) but I finally got this is into a nice working form - maybe it will be useful for someone. It is called like this: [code] void TestParallelSort() { vector<double> Numbers; Numbers.push_back(3.4); Numbers.push_back(4.5); Numbers.push_back(1.2); vector<string> Names; … | |
It seems like SO often I need to attach a "valid" flag to a standard type. For example - I have a function called "CalculateLunchTime" that I pass a vector of times. If the vector has 0 elements, they did not take a lunch, so the duration is 0 minutes. … | |
If I use the uncommented 3 lines for getting an int out of a stringstream, the value in MPV is wrong. However, if I make a new stringstream, then it works fine. I thought setting .str("") was essentially resetting the stringstream? [code] line = ""; getline(fin, line); //get fourth line … | |
I have a delete button which does this: [code] TTDataSet.PunchEventTable.Rows(dgvData.SelectedRows(0).Index).Delete() [/code] The problem is that if I delete row 0 (the 0th index in the DataGridView and in the underlying table, all is well. But now row 1 in the table corresponds to row 0 in the DataGridView, so if … | |
I have tried to make a SumVector function for all types, but if it is called with a vector of unsigned char's, it will do something special. Here is what I tried, but I get a multiple definitions of the function compiler error. [code] template <typename T> void SumVector(vector<T> &V) … | |
I want to do something like this [code] template <class T> vector<T> DereferenceVector(vector<T*> &PointerVec) { vector<T> ObjectVec; for(unsigned int i = 0; i < PointerVec.size(); i++) ObjectVec.push_back(*PointerVec[i]); return ObjectVec; } [/code] and call it with [code] void TestDereferenceVector() { vector<double*> a(10); vector<double> b = DereferenceVector(a); } [/code] That seems to … | |
If I do this, I get "warning: address of local variable returned". [code] unsigned char* CharArray(void) const { unsigned char arr[3]; arr[0] = R_; arr[1] = G_; arr[2] = B_; return arr; } [/code] So the reason for that is that the memory allocated for arr[] is only available within … | |
A friend convinced me to store a vector of pointers in my class: [code] vector<Point*> Points; [/code] In my class instead of a vector of "real" objects (what do you call this?). The problem now is that there are several functions (out of my control ie. in a library) that … | |
I have a function that I call recursively, but I want to keep track of a maximum through the entire process. This is what I am doing: [code] void Intersect(double &MaxDistance) { if(something) MaxDistance = something; Intersect(MaxDistance); } [/code] Is that correct/reasonable? Something doesn't seem to be working and I'm … | |
There was another thread about this ([url]http://www.daniweb.com/forums/thread114737.html[/url]) but it didn't seem to be resolved? If I have a vector of int's and another vector of the same length of corresponding names, I would like to sort the ints and have the names "follow" [code] vector<string> Doubles; Doubles.push_back("Name1"); Doubles.push_back("Name2"); Doubles.push_back("Name3"); vector<int> … | |
[code] double P = 3.5/(.1 * sqrt(2.0*3.14159)) * exp(-pow(5.0,2) / (2.0*pow(.1,2))); cout << P << endl; if (P==0) cout << "P is zero!" << endl; [/code] Is this underflowing so it is getting rounded to zero? The problem is that I am taking the log of this, so if it … | |
I wrote a pause function: [code] void Pause(void) { printf("Paused...\n\n"); fgetc(stdin); } [/code] It generally works fine (hit enter to continue). But one program doesn't seem to want to stop at all... [code] if(P == 0) { cout << "P=0!" << endl; //just as another attempt to stop it , … | |
Is there anyway to get the calling function? ie [code] void A() { if (A() was called from B() ) do something; else do something else } [/code] Is this possible? Dave | |
In integration.h I have this [code] class FunctionClass { public: virtual double f(const double x) = 0; }; [/code] Then in probability.h, I have this [code] #include "integration.h" class Mass1 : public FunctionClass { public: double Clutter; Mass1(double c) : Clutter(c) {} double f(const double x) { return Clutter * … | |
I just learned about returning a reference... and it seems to me that I can delete my mutators now? ie. [code] class foo { int A; //mutator void set_A(const int a) {A=a;} //accessor int get_A() {return A;} } int main() { foo MyFoo; int b = MyFoo.get_A(); //get MyFoo.set_A(4); //set … | |
I would expect this to ouput the 5 doubles, but instead I get the output below. [code] vector<double> a(5); a.push_back(1.2); a.push_back(1.3); a.push_back(1.4); a.push_back(1.5); a.push_back(1.6); vector<double>::iterator i; i = a.begin(); while( i != a.end() ) { cout << *i << endl; i++; } [/code] [code] 0 0 0 0 0 1.2 … | |
Anyone know a good, simple set of classes to do thing like cartesian to spherical conversion, coordinate system transformations, etc? I wrote some of this stuff, but my code keeps breaking because of "special cases" that I have not handled. I just want to be able to use this stuff … | |
I put together this little example to test my sanity, and it failed! [code] #include <iostream> #include <fstream> #include <vector> #include <string> #include <sstream> using namespace std; /* Example.txt 23 test 4.5 */ int main(int argc, char *argv[]) { string Filename = argv[1]; cout << "Filename: " << Filename << … | |
Anyone see a problem with this line? My Color header is included (I use it all the time). map and vector are included. [code] void GenerateColors(map<Color<unsigned char>, int> &Map, vector<Color<unsigned char> > &List, int num) [/code] I don't see anything wrong? Dave | |
This problem comes up quite a bit for me. I'll have a project that I work on for a couple months (the point is that it is a large project with multiple classes, etc). As an example, say I made a program that draws a square. So I have this … | |
I have seen some examples like this [code] p.class1 { some stuff } p.class2 {some stuff } [/code] and some like this [code] class1.p {stuff} class2.p {stuff} [/code] In one case, the class name is before the dot, in the other case the class name is after the dot. What … | |
I am very new to css. I was looking at a css file I found online and trying to figure out what everything does. I am confused with the following couple of things. Please let me know if anything I say is wrong! This on sets up some properties of … | |
Here is my demo.css [code] #sidebar {} #sidebar ul { list-style-image: url(images/bullet.gif); } ul { list-style-type: circle; } [/code] and demo.html [code] <html> <head> <link REL="StyleSheet" TYPE="text/css" HREF="demo.css"> </head> <body> <ul class="sidebar"> <li> Test1</li> <li> Test2</li> </ul> <ul> <li> Test3</li> <li> Test4</li> </ul> </body> </html> [/code] I would expect the … | |
I am trying to output 00001 instead of just 1, so I do this: char pos[5]; sprintf(pos, "%05d", 1); string Index = (string) pos; It works just as I'd expect - if I cout << Index it says 00001 However, it is breaking something totally unrelated. On the next line, … | |
Is this flash (how do you tell?) [url]http://www.kwikkopy116.com/[/url] Is there any way to develop a flash site on linux? I've been unable to find anything about it! If not, is there any other way to make a page like this that can be done on linux? Thanks! Dave | |
With printf, you specify the output type like this unsigned char a; printf("%u", a); but with cout, cout << a; there is no type required. Do you have to cast the variable in order to see a reasonable output cout << (int)a; or something like that? How do you know … | |
I want to do something like this: unsigned char r[3] = {255, 0, 0}; map<unsigned char[3], int> ColorList; ColorList[r] = 1; But I get the following: error: array used as initializer How else would I set the r element of the map? Thanks, Dave | |
I would like to make a list of colors with an associated color index ie 1, [1 0 0] 2, [0 1 0] 3, [.4 .4 .4] etc So I could make a map map <int, double*> ColorMap; Then I could look up the color by its index like this: … | |
I have a base class called ModelFile I have derived classes called ObjFile and VtkFile that I would like both to use << from ModelFile. However, since << is an external function, [code] ostream & operator << (ostream &output, const ModelFile &Model) { output << "Num Vertices: " << Model.NumVertices() … | |
I would like to declare the type of an object based on user input. Ie. I would like to do the following: [code] string obj = //get from command line arguments if(Format == "obj") { ObjFile Obj; Obj.Read(InputFile); Obj.DoSomething(); Obj.Write(OutputFile); } else if (Format == "vtk") { VtkFile Vtk; Vtk.Read(InputFile); … | |
I have a base class called "ModelFile" which I derive several types of 3D model file classes from. Many of these types of files are just a set of points, so in the base class I have a vector<Point> member. Some of the derived file classes also have vector<Triangle> members. … | |
I have a Triangle class which has members [code] Point P1, P2, P3; [/code] So generally I pass the constructor 3 points. [code] Point A(1,1,1); Point B(1,1,0); Point C(0,0,1); Triangle T(A,B,C); [/code] Then I have a bunch of functions that I can pass point's to such as to find intersections … | |
I have done some html many years ago, but never css. I downloaded a template [url]http://www.freecsstemplates.org/preview/exposure[/url] But something has gone slightly wrong. When I use it on my website [url]http://doriad.myrpi.org/[/url] you can see that the bottom "grey" bar is above the blue line, where in the example the grey is … | |
Does anyone know how I can count how many times a pdf has been downloaded from my site? Maybe someone has a php script or something that does this? Thanks! Dave | |
Normally I call this function like this [code] void MouseButton(int button, int state, int x, int y); ... glutMouseFunc(MouseButton); [/code] But now I would like to pass a member function instead of a "real" (non-member? whats the word for this?) function. [code] class Plot { void Plot::MouseButton(int button, int state, … | |
I need to do something like this: [code] ifstream infile(Filename.c_str()); //ifstream infile(Filename.c_str(), ios::binary); string line; ///////////// Read Header //////////// //read magic number getline(infine, line); while(line[0] == "#") getline(infile, line); MagicNumber_ = line; //more ascii stuff ...... //start reading binary data int m; infile.read(reinterpret_cast < char * > (&m), sizeof(m)); [/code] … | |
I would like to have a global way to do something like this [code] #ifdef GRAPHICS //do some stuff that relies on graphics libraries that may or may not be installed #endif [/code] The problem with defines is that they have to be defined in every file, or at least … | |
I have been using GSL, but I find it very awkward to work with. Does anyone have a recommendation for another one to try? I can't seem to find any on google. Thanks, David | |
It seems that writing ascii files changed significantly from c to c++. It moved from file pointers and things like that to being very easy, like [code] ofstream myfile; myfile.open ("example.txt"); myfile << "Writing this to a file."; myfile.close(); [/code] However, from googling it seems that binary file reading/writing has … ![]() | |
I have been using vector in c++ lately, but I needed to speed up my code a bit so someone recommended I use regular arrays. My question is 2 part - 1) I thought you couldn't do this!!?? For some reason it is working with no problem? [code] int a=2; … | |
I want to be able to do this: Pass a parameter to my main program like "parallel = yes" and then many functions down in the hierarchy (ie main calls "Function1" which calls "Function2" which calls "Function3", etc) I need to see the value of "parallel". I'd hate to have … | |
I have a very simple class [code] class Point { public: Point(); Point(double x, double y); double x_; double y_; } [/code] the problem is, I can't assign my class to another instance, ie: [code] Point A(2,4); Point B(); B = A; [/code] It says the lvalue must be modifiable. … | |
I have a function double Max(vector<geom_Point3> &Points, int n); Then in another class, I have a private member: vector<geom_Point3> Vertices_; and in a class function, I call: min_x = Min(Vertices_, 0); however, I get [code] error: qualifiers dropped in binding reference of type "std::vector<geom_Point3, std::allocator<geom_Point3>> &" to initializer of type … | |
I am trying to overload * [code] class Vector3 { public: geom_Vector3 operator * (double d);//overload * from the left }; geom_Vector3 operator * (double d, geom_Vector3 &V); //overload * from the right [/code] The problem is this works [code] geom_Vector3 V(1,2,3); cout << -1 * V << endl; [/code] … | |
Right now this is my setup: I have these classes Point2 Point3 Vector2 Vector3 Ray2 Ray3 Both Point classes and both Vector are independent. Ray2 contains a Point2 and a Vector2 object, and Ray3 contains a Point3 and a Vector3 object. I have two questions. 1) Should I somehow just … | |
I have a function Scan.MakeLinearGrid() which returns a vector<vector<Vector3> > I have another function that is made to accept this type of thing: Scan.setAngleList(vector<vector<Vector3> >); But if I call it like this: [code] Scan.setAngleList(Scan.MakeLinearGrid()); [/code] it says [code] error: initial value of reference to non-const must be an lvalue Scan.setAngleList(Scan.MakeLinearGrid()); … | |
(see next post for the question about makefiles!) I have this line in ScanScene.h [code] bool ScanScene(LiDARScan &Scan, LiDARScanner &Scanner, vector<geom_Triangle> &Scene); [/code] and in ScanScene.cpp [code] bool ScanScene(LiDARScan &Scan, LiDARScanner &Scanner, vector<geom_Triangle> &Scene) { ... } [/code] then in another file, I [code] #include "ScanScene.h"; int main() { LiDARScan … | |
Is there a way to check for a keypress every time through a loop without forcing a key to be pressed. ie. if you use scanf, the loop will not continue unless a key is pressed. I'd like to say "if a key was pressed, handle it. If not, keep … | |
Anyone know where I can get an implementation of this? Some code to read in a set of vertices/triangles and then do some simple intersection tests? If you can point me in the right direction that'd be great! Thanks, Dave |
The End.