265 Discussion / Question Topics
Remove Filter 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've spend a lot of time working on a bunch of classes (point, vector, ray, triangle, plane) etc to work with these objects and their intersections in c++. However, now that I am ready to do a full scale project with them, I am finding they are terribly slow! I've … | |
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 | |
I have a file that contains lines like: 2/3/4 5/6/7 8/9/10 and I want to extract the 2, the 5, and the 8 So I am parsing the line by the ' ' delmiter to get 2/3/4 5/6/7 8/9/10 then I need to parse each of those to get the … | |
I have about a 1gb data file that needs to be read at the beginning of my program. This takes about 2 minutes to do. I feel like the answer is "no way", but here is my question. In matlab, there is the concept of a "workspace". I can ready … | |
I have a function: void CreateCostGrid(vector<ScanPoint> &Data, int whichcol, vector<LiDARScan> &LiDARGrid); That I call like this: CreateCostGrid(TestScan.getColumn(GoodCols.at(testcol)), GoodCols.at(testcol), ModelScans); But I get this: error: initial value of reference to non-const must be an lvalue CreateCostGrid(TestScan.getColumn(GoodCols.at(testcol)), GoodCols.at(testcol), ModelScans); (There is an arrow underneath the T in TestScan, i guess indicating that … | |
I'd imagine there is a much better way to do this... [code] vector<double> Model; //code to fill Model vector<double> V1; for(int i = StartModel; i <= EndModel; i++) V1.push_back( Model.at(i) ); [/code] | |
I want to do something like this [code] #include <string.h> #include <iostream> using namespace std; int main() { MyFunc("test"); return 0; } void MyFunc(const char* Filename) { cout << strcat(Filename, ".tst") << endl; } [/code] but it tells me that my const char* cannot be used where it is expecting … | |
This doesn't seem to behave as I would expect (as it does in matlab, for example). I want to execute a command, but give some readable output instead of the often very messy auto-generated error (index out of range or something). [code] try { MyFunction(1,2); } catch(char* str) { cout … | |
I have to call a function in the form f(void* params) I would like to pass two vector<double> to this function. I suppose I should make a struct struct MyParam_t { vector<double> myvector1; vector<double> myvector2; }; and then somehow fill it and pass it to the function. Someone recommended that … | |
I ran this: [code] cout << "has nan q?" << numeric_limits<int>::has_quiet_NaN << endl; cout << "has nan s?" << numeric_limits<int>::has_signaling_NaN << endl; cout << "has nan q?" << numeric_limits<double>::has_quiet_NaN << endl; cout << "has nan s?" << numeric_limits<double>::has_signaling_NaN << endl; [/code] and I get 0 0 1 1 why would … | |
I have some code like this: [code] vector<double> Saved; for(int i = 0; i<10; i++) { if(some condition on i) Saved.push_back(i); } [/code] Then I want to see what order the things were saved... so naturally I do cout << Saved.at(0) << endl << Saved.at(1) << endl; But to my … | |
When trying to compile my code with g++ i get this: MayaFunctions.h:5:27: error: calling fdopen: Bad file descriptor in that line, I simply have #include "AnotherFile.h" Google told me this has something to do with precompiled headers, but I can't figure out how to turn them off. 1) how to … | |
I keep getting this error: this application has failed to start because MFC80.dll was not found. In the past, when I've got this error i've played around with "Runtime library", switching it from /MDd to /MD to /MTd......etc etc then I turn off and on the manifest files then I … | |
I seem to be able to write as many characters as I want into "buffer" even though I declare it as length 1 - why is this? [code] string teststring = "teststring"; cout << teststring << endl; char buffer[1]; itoa(34567,buffer,10); teststring.append(buffer); cout << teststring << endl; [/code] Thanks! Dave | |
I have 2 classes, Edge and Point. Edge contains Point P1 and Point P2 as private memebers. Edge has accessor functions [code] Point getP1() { return P1; } [/code] and the same for P2. Point has << overloaded - [code] ostream & operator << (ostream &output, Point &p); [/code] I … | |
I had a global variable that could be seen by all of my functions. I was getting too many functions in the same file, so I made functions.h and functions.cpp. I put the function definitions in functions.cpp and the declarations in functions.h. In main.cpp, I include functions.h. The problem is, … |
The End.