227 Archived Topics
Remove Filter I am trying to compile some code (Example.cpp from here: [url]http://www.rpi.edu/~doriad/Daniweb/maxflow/[/url]). I am getting [code] Example.cpp:(.text+0x38): undefined reference to `Graph<int, int, int>::Graph(int, int, void (*)(char*))' [/code] This is clearly a template instantiation problem. I see that there is a file called instances.inc that defines the <int,int,int> class, do I need … | |
Is there anyway to get images to be the "correct" size - i.e. fit the width of the text? This is what currently happens: [url]http://engineeringnotes.net/personal/pictures.shtml[/url] Thanks, Dave | |
I'm still very new to css, so I'm sure this is just some really silly thing: [url]http://engineeringnotes.net/personal/[/url] Does anyone know why the text is hanging off the left side of the page (on the "home" page and the "publications" page? Thanks, Dave | |
When debugging my code, I put a break point at this line: [code] std::set<unsigned int>::iterator it; [/code] When I step over that line, I get "Debugger reported the following error: cannot access memory at address 0x10". I am using KDevelop that ships with Fedora 11. I've used that line of … | |
I have a function like this: [code] bool MyFunction(dist) { if(dist < 1.2) { std::cout << "Passed test!" << std::endl; return true; } else { std::cout << "Failed test!" << std::endl; return false; } std::cout << std::endl; } [/code] gcc tells me "warning- control reaches end of non-void function". However, … | |
I made 2 classes, Point and Point3D: Point.h: [code] #ifndef POINT_H #define POINT_H #include <iostream> template <typename T> class Point { protected: T X,Y,Z; public: Point(const T x, const T y, const T z) : X(x), Y(y), Z(z) {} T getX() {return X;}; T getY() {return Y;}; T getZ() {return … | |
This may be a gdb problem or a KDevelop problem, but I'm hoping it's a c++ problem so it's more easily fixed! If I "execute" my application either in KDevelop or from a terminal, it finishes and terminates without any problems. However, if I step through the code, when it … | |
I have written a small program (it depends on big libraries, so I will not post the actual code) that performs correctly, but segfaults at the very end (main return). [code] int main() { ..... my code here... std::cout << "Finished." << std::endl; return 0; } [/code] I see "Finished." … | |
If I have a class in a namespace, like this: [code] #ifndef MyClass_h #define MyClass_h namespace NyNamespace { class MyClass { public: typedef double MyType; MyType Read(); }; } #endif [/code] And the implementation: [code] #include "MyClass.h" namespace MyNamespace { MyClass::MyType MyClass::Read() { MyClass::MyType A; return A; } } [/code] … | |
I have an abstract class NetworkTest and some derived classes PingTest, SMTPTest, and POP3Test. Each Test class overrides a Run() function and has it's own private member variables. I have a txt file for each type of test - ping.txt, pop3.txt, smtp.txt that defines the tests that should be run, … | |
I have a superclass NetworkTest and 3 derived classes PingTest, Pop3Test, SMTPTest. I want to create a big list of all the tests, like this: [code] Dim Tests As New List(Of NetworkTest) Dim PingTests As List(Of PingTest) = ReadPingTestsFromFile(PingFile) Tests.AddRange(PingTests) Dim Pop3TestResults As List(Of Pop3Test) = ReadPOP3TestsFromFile(POP3File) Tests.AddRange(Pop3TestResults) Dim SMPTTests … | |
I know you can't usually define things in the class like this: [code] class MyClass { double DefaultForward[3] = {0.0, 1.0, 0.0}; }; [/code] but I have some values that don't really make sense to set in the constructor - they are more "deeply connected" as THIS SHOULD ALWAYS BE … | |
(As a warning - if at any point you think "umm why don't you just use X to get your 2 column display - I'm all for that! This is the only way I came up with). I want to end up nice looking display of data on the form … | |
There is a pure virtual const function declared like wayyyy up the inheritance hierarchy that I need to override, but I would like to override it with a non-const function. I tried and it just complained that the pure virtual const function const was not implemented. I got around it … | |
I have a class called Scanner which casts rays into a 3d scene and records the resulting intersections. It has the following type of properties: Location (a 3d point) Forward (a 3d vector) Up (a 3d vector) min/max angle (the bounds of where to cast rays) theta/phi step (the directions … | |
The problem is on the "MyIter = " line: [code] class OrientedPoint { .... class variables ... std::map<std::string, double> DoubleValues; ..... bool OrientedPoint::getDoubleValue(const std::string &ValueName, double &Value) const { std::map<std::string, double>::iterator MyIter; MyIter = DoubleValues.find(ValueName); [/code] The error produced is: [code] In member function 'bool OrientedPoint::getDoubleValue(const std::string&, double&) const': error: … | |
Is there a way (without overloading) to call a function like this [code=cplusplus] GetValue("one"); //AND std::string test("one"); GetValue(test); [/code] The function is simply: [code=cplusplus] int GetValue(const std::string &MyString) { return MyMap[MyString]; } [/code] This overload does the job: [code=cplusplus] int GetValue(const char* MyString) { return MyMap[MyString]; } [/code] But that … | |
I don't understand why can you do this: [code] Employee *emp; if (condition1) emp = new Employee(); else if (condition2) emp = new Manager(); [/code] but not this: [code] Employee emp; if (condition1) emp = Employee(); else if (condition2) { emp = Manager(); [/code] Maybe this is a TERRIBLE idea, … | |
I'm trying to start writing tests for all of my functions as per Test Driven Development. My question is, say I construct a test for "rotate vector". It would be something like this: [code] int TestRotateVector(const Vector &V) { Vector Original(1.0, 2.0); Vector Rotated = Original.Rotate(10); //rotate 10 degrees if(Rotated … | |
i.e. [code] class A { int x = 5; }; [/code] I saw a mailing list post from October 08 where a guy asked if this was going to be added. gcc 4.4 was released April 09, so I would assume it would have been added by then? I haven't … | |
If I do something like this: [code] print "%08d" % 2 [/code] It will print '00000002'. However, I want to change the "8" to a "3" at runtime (to get '002' instead). I tried this: [code] MyLength = 3 print "%0" + str(MyLength) + "d" % 2 [/code] but I … | |
I'm just starting python and it seemed reasonable to go ahead and learn the new version. I read that numpy wont be available for python3 until at least 2010. All I need is a basic "vector", "matrix", and some basic functions like matrix/vector multiplication. Is anything like this available for … | |
If I have /home/doriad/Scripts/Python/ and inside I have a bunch of folders, ie Geometry, Math, Other, etc that each contain scripts (.py files), is there a way I can just add /home/doriad/Scripts/Python to PYTHONPATH and then somehow [code] from Geometry/Spherical import * [/code] rather than having to add every subdirectory … | |
I want to make an input stream parser capable of handling input in any of the following forms: [code] x y z x,y,z x, y, z (x,y,z) (x, y, z) [/code] Is there a clever way to do this? Or do I have to check the first character, if it … | |
Is it possible to indicate that a class function you are calling is static? [code] class Point { std::string name; public: Point(){} static void DisplayName() { std::cout << "Point" << std::endl;} }; int main() { Point.DisplayName(); //this doesn't indicate the the member function is static //maybe something like this: //static_call(Point.DisplayName()); … | |
I have a "Tools" class which contains a lot of functions I commonly use. One is a parallel sort. I pass it a vector of Objects and a vector of indices, and it sorts the Objects and sorts the indices the same way (so the corresponding index is in the … | |
I was looking at this: [url]http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.18[/url] I don't understand [code] File f = OpenFile("foo.txt"); [/code] It seems like File is one class, and OpenFile is a separate class, so how can you assign an OpenFile to a File? Also, is it necessary to have this second class? Why not something … | |
To redirect clog, I have been using this: [code] std::streambuf* clog_save; std::ofstream ofs; clog_save = std::clog.rdbuf(); ofs.open(LogFilename.c_str()); std::clog.rdbuf(ofs.rdbuf()); cout << "Test cout." << endl; std::clog << "Test log." << endl; std::clog.rdbuf(clog_save); ofs.close(); [/code] However, it seems like bad "code reuse" practice to have to put this in every program I … | |
I usually make a matrix like this [code] from Numeric import * A=zeros([3,3]) print str(A[0,1]) #access an element [/code] I would like to store a pair of values in each element, that is have a matrix where the (0,0) element is (2.3, 2.4), the (0,1) element is (5.6,6.7), etc. Is … | |
I found some code to parse command line arguments (is there an easier way? sed always seems so complicated...) [code] #!/bin/bash for i in $* do case $i in --files=*) FILES=`echo $i | sed 's/[-a-zA-Z0-9]*=//'` ;; --default) DEFAULT=YES ;; *) # unknown option ;; esac done echo $FILES echo "File … | |
I need to get an unknown number of file names from the command line, ie ./python MyScript.py --Files 1.txt 2.txt 3.txt [code] parser.add_option("-n", "--NumFiles", type="int", help="Number of files") parser.add_option("--Files", nargs=options.NumFiles, help="a triple") (options, args) = parser.parse_args() [/code] Clearly this will not work because options.NumFiles is not available until after parse_args() … | |
I want to parse some simple arguments from the command line. This shows all of the arguments: [code] #!/usr/bin/python import sys #print all of the arguments for arg in sys.argv: print arg [/code] but I want to handle something like [code] --file a.txt [/code] or [code] --x 12 --y 13 … | |
I tried to do this to redirect the clog output to a file: [code] ofstream ofs("file.log"); clog.rdbuf(ofs.rdbuf()); clog << "Logged." << endl; ofs.close(); [/code] It worked (the file contains the text), but the program segfaults. I read that you have to "restore" the original buffer, so I tried this [code] … | |
A friend of mine said that python could be used to make simple GUIs (ie. a couple of buttons and a text box). I googled "python gui" and it looks like there are 30934 libraries to make GUIs. Is there a "standard" or "built in" one? Thanks, Dave | |
Does anyone have a good 2 line summary of WHEN to use perl/python/bash/etc? To do easy-ish things, they can clearly all be used, but there is likely an ideology behind each that indicates WHEN/WHY to use them. For example, I use VB if I want easy GUI, c++ if I … ![]() | |
I am trying to do this [code] #!/bin/bash for i in 1 2 3 4 5; do File1="$i.txt" File2="$i.obj" ./Test $File1 $File2 #save i and the result of the program somehow done; [/code] For example, at the end I would like to have a file like this [code] 1 3.4 … | |
I have used boost's progress bar (it outputs ***** from 0 to 100% complete) to track the progress of long loops. It would also be nice to be able to see a counter along with that, like if I run 1000 tests, the *'s will go from 0 to 100%, … | |
I am trying to write a pretty straight forward algorithm (agglomerative clustering), but the details are getting pretty hairy. (A cluster is simply a group of points. The idea is to take a list of points and decide which are "grouped" or "clustered" close together.) Here is the outline: Input: … | |
On the line [code] set<T>::iterator iter; [/code] I am getting "expected ';' before 'iter'" [code] #include <vector> #include <set> using namespace std; template <typename T> vector<T> UniqueElements(const vector<T> &V) { set<T> s; s.insert(V.begin(), V.end()); vector<T> Elements; set<T>::iterator iter; return Elements; } [/code] Can anyone see why? It compiles fine if … | |
This simple example fills a vector with numbers 0-9. Then I use find() to find where the 7 is. Then I saw online you can get the index by simply subtracting V.begin() from the iterator that find() returns. Has - been overloaded for iterators to do some magic and return … | |
Currently, my index.html is like this [code] <html> <head> <title>EngineeringNotes.net</title> <link href="style.css" rel="stylesheet" type="text/css" media="screen" /> </head> <body> <div class="header"> <div id="logo"> <h1>EngineeringNotes.net</h1> </div> <div class="menu"> <ul> <li><a href="mailto:daviddoria@gmail.com">Contact Me</a></li> <li><a href="phpBB3">Forums</a></li> <li><a href="Ideology.html">Ideology</a></li> </ul> </div><!-- end menu --> </div><!-- end header --> <div class="page"><!-- start page --> <div class="sidebar"><!-- … | |
According to this: [url]http://www.parashift.com/c++-faq-lite/templates.html#faq-35.13[/url] One way to keep only the function declaration in the .h file is to do this [code] ////////// file: Tools.h #include <iostream> #include <vector> using namespace std; template <typename T> T Sum(vector<T> &V); [/code] [code] ///////// file: Tools.cpp #include "Tools.h" #include <iostream> #include <vector> using namespace … | |
To remove duplicates from a vector, my first thought was to insert them all into a set, it would take care of the uniqueness of the elements, and then read them back out into my vector. However, I have a vector<Point>, where Point is a point in 3d space (ie. … | |
I was reading about the new "tuple" type coming in c++0x, and I decided to try it. I saw that if you give a compiler flag -std=c++0x it will work. So I did it, and then #include <tuple> works and everything was good. Then I decided to try the default … | |
Is there a built in type to store UNordered pairs? ie. I want these [code] pair<double, double> a(4.0, 5.0); pair<double, double> a(5.0, 4.0); [/code] to be equal. Do I have to make a wrapper and override == ? Thanks, Dave | |
I often have this situation [code] class OrientedPoint { private: Point P; Vector N; Color C; bool valid; public: //////////// Constructors ////////// OrientedPoint() {} OrientedPoint(const Point &Coord); OrientedPoint(const Point &Coord, const Vector &Normal); OrientedPoint(const Point &Coord, const Color &C); OrientedPoint(const Point &Coord, const Vector &Normal, const Color &C); [/code] where … | |
I'm just trying to figure out how this stuff works. I wrote this function: [code] #include <algorithm> #include <vector> double VectorMax(const vector<double> &a) { vector<double>::iterator pos; pos = max_element (a.begin(), a.end()); return *pos; } [/code] and call it with: [code] vector<double> Numbers; Numbers.push_back(3.4); Numbers.push_back(4.5); Numbers.push_back(1.2); cout << VectorMax(Numbers) << endl; … | |
I am trying to use the for_each from stl algorithm. [url]http://www.cplusplus.com/reference/algorithm/for_each.html[/url] [code] #include <algorithm> #include <vector> #include <iostream> template <typename T> void OutputObject(const T &obj) { cout << obj << endl; } template <typename T> void OutputVector(const vector<T> &V) { for_each (V.begin(), V.end(), OutputObject); cout << endl; } [/code] I … | |
I found this while googling for something [url]http://msdn.microsoft.com/en-us/library/ms177203(VS.80).aspx[/url] I tried it (with g++) and it seems to be a syntax error - is this like something specific to Visual Studio or something? Dave | |
Is there a reason to use [code] cout << static_cast<int>(thing); [/code] instead of [code] cout << (int)thing; [/code] ? Thanks, Dave |
The End.