- Strength to Increase Rep
- +7
- Strength to Decrease Rep
- -1
- Upvotes Received
- 51
- Posts with Upvotes
- 49
- Upvoting Members
- 26
- Downvotes Received
- 0
- Posts with Downvotes
- 0
- Downvoting Members
- 0
["Objects that are instances of an inner class exist within an instance of the outer class"](http://docs.oracle.com/javase/tutorial/java/javaOO/nested.html) Even though I attempt to create an independent instantiation of the inner class, the outer class is always there because of the statement above. ##Is that ture? If true, then that would also mean … | |
Re: ##You can't return a pointer from off the stack. Add the error handling #include <cstdio> #include <iostream> using namespace std; struct student { int SUB[3]; }; struct AVGPCT { float avg; float pct; }; AVGPCT* CALC(student *A) { int x,y; //--------------------------------------- // Have to allocate the memory here AVGPCT *D … | |
Re: Yes, need more context. Post more. And tell us what it is doing that makes you say that it doesn't work. | |
Re: Read this http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html and look at the section **Rounding Error**. ##Play around with this #include <iostream> #include <iomanip> #include <cmath> // Might need this later #include <cfloat> using namespace std; int main(){ // a / b = c = c // (1/9) / (1/3) = 3/9 = 1/3 float a(1.0f/9.0f),b(1.0f/3.0f),c(1.0f/3.0f); … | |
Re: You didn't allocate memory for the cell inside the INST. [code] for ( j = 0; j < i; j++ ) { top_inst_list[j] = (INST *)malloc(sizeof(INST)); top_inst_list[j]->name = (char *)malloc (sizeof(char) * 10); // You need to allocate memory for the CELL before you start to access // top_inst_list[j]->cell->name top_inst_list[j]->cell … | |
Re: ##Would this work http://www.cplusplus.com/reference/std/locale/collate/hash/ | |
Re: ##See comments in code #include <stdio.h> #include <unistd.h> #include <fcntl.h> #include <sys/mman.h> #include <sys/types.h> #include <ctype.h> //---------------------------------------------------------- // Added for fstat #include <sys/stat.h> int main(int argc, char * argv[]){ //---------------------------------------------------------------------------- // Added for fstat struct stat sb; int fd, pagesize,i; char *data, x; if (argc != 2){ //-------------------------------------------------------------------------- // Here … | |
Re: ##If using GCC version < 4.7.0 (me 4.6.3) need to uncomment out this as Mikael Persson indicates // For GCC version < 4.7.0, use this replacement for the template alias: // template <typename T> // struct locked_ptr { // typedef const detail::locked_ptr_impl<T>& type; // }; ##And replace all locked_ptr<const std::string> … | |
Re: If you are inserting at the front each time, DataAt(i) will always return the first element you added. Ex: InsertAtFront(22): 22 DataAt(0) = 22 InsertAtFront(33): 33, 22 DataAt(1) = 22 InsertAtFront(44): 44, 33, 22 DataAt(2) = 22 etc ... | |
Re: > /* Memory allocation */ > array = (int**)malloc(sizeof(int) * ROWS); ##Should be /* Memory allocation */ array = (int**)malloc(sizeof(int*) * ROWS); sizeof(int) and sizeof(int *) would be different on 64-bit machine. | |
Re: ##@dyl_ham, your last try was really close. Just move some things around. #include <iostream> #include <fstream> #include <cstdio> #include <cerrno> using namespace std; ifstream * openInputFile() { string fileName; cout << "Please enter a valid file name: "; cin >> fileName; //--------------------------------------------------- // You have the file name, just use … | |
Re: ##Try if(childpid > 0){ //parent close(pipe2[1]); close(pipe1[0]); client(pipe2[0], pipe1[1]); //--------------------------------------------------- // I moved these, you have to close the pipes // so the server can exit and then the wait // will catch the exit of the server. close(pipe2[0]); close(pipe1[1]); wait(&status); exit(0); } ##Now `while(read(readfd, am, sizeof am) > 0)` … | |
Re: ##This works for me and I'm using the same g++ (gcc version 4.1.2 20080704).## #include <iostream> using namespace std; typedef int DOMNode; class MyDOMNode { public: MyDOMNode (DOMNode* node): mDomNode (node) { cout << "Constructor: " << node << endl; } bool operator== (const MyDOMNode& rhs) { if (mDomNode == … | |
Re: ##See if this helps, look at comments.## #include <iostream> #include <string.h> #include <sstream> using namespace std; struct Item { string itemDescription; int quantity; float wholesaleCost, retailCost; string dateAdded; }; int main(){ Item temp; //file.read((char*)&temp.itemDescription, readsize); //####################################### // Comment this out for this to work read(1,(char*)&temp.itemDescription,4); //##################################################### // // temp.itemDescription // … | |
Re: ##See if this helps, look at the comments.## #include <string.h> #include <stdio.h> //####################################### // This must be what your structure // looks like struct { char *nome; char *identificadorNum; char *quantStock; char *limMin; char *consumoMed; } ingredientes[4]; //####################################### // This is what it should look like struct { char nome[10]; … | |
Re: Just ran you code and it worked for me: #include <iostream> #include <string> #include <cstdio> #include <curl/curl.h> int main(void) { CURL *curl; curl = curl_easy_init(); if(!curl) { std::cout << "Unable to initialize cURL interface" << std::endl; return -1; } std::string curl_url = "https://www.cia.gov/"; curl_easy_setopt(curl, CURLOPT_URL, curl_url.c_str()); curl_easy_setopt(curl, CURLOPT_USERAGENT, "libcurl-agent/1.0"); curl_easy_setopt(curl, … | |
Re: I don't think you want to have it scoped to the Circle class. If it was then you wouldn't have to be a friend. | |
Re: When you get to it, void B::add(int id, string name, int age){ A *a; a=new A; a->setid(id); a->setname(name); a->setage(age); list.push_back(*a); } is leaking memory. You define list as `vector<A> list;` and in the add function allocate memory for an A class but when you add it to the list it … | |
Re: Using a recursive function as well. I just have one more bug (I think). I thought that function was getting to complex but maybe not. Got to solve it, it's consuming me now. | |
Re: Change line 223 from `dobule weightInKg = convertLbToKg(weight);` to `weightInKg = convertLbToKg(weight);` You defined weightInKg at line 201 and then again at line 223 but then you used it in 275. But were you set it at line 223 is a different scope then the one defined at 201. | |
Re: What do the values in the matrix represent? And why is T1 -> p1 T2 -> p2 T3 -> p3 T4 -> p1 the best? Trying to understand your problem a little more. | |
Re: > I tried to do linear probing in the above ... Looking at the link you gave, it looks like they want you to use link-lists for the collisions because in the section were it talks about >b. when requested, analyze the efficiency of the hashingalgorithm for this set of … | |
Re: Line 152 you are using 1for the first index, it should be i. cout << " " << feedback[i][3]; | |
Re: Should `generate_combination()` be an operation of the class bruteFrce? Like `void bruteFrce::generate_combination(int)` or should it really be outside the scope of the class bruteFrce? | |
Re: Use erase: http://www.cplusplus.com/reference/string/string/erase/ `string& erase ( size_t pos = 0, size_t n = npos );` "pos: Position within the string of the first character to be erased." "n: Amount of characters to be removed." void setSecretCode (char code[4]) { string colors = "RGBYO"; int pos; srand(time(NULL)); pos = rand() % … | |
##I was working on something and saw this oddity, thought I would share it. $ ./a.out in.val = 86.3115158 -> Its a valid floating point number out1.val = nan -> Swapped it and now its a NaN! That's OK swap it back. out2.val = 86.4365158 -> What, its not the … | |
Re: Its wraping around. $ ./a.out i(0) f1(9) f2(-8) <------ Should have stopped here i(1) f1(12) f2(-6) i(2) f1(18) f2(-4) i(3) f1(24) f2(-3) i(4) f1(36) f2(-2) i(5) f1(72) f2(-1) i(6) f1(-72) f2(1) i(7) f1(-36) f2(2) i(8) f1(-24) f2(3) i(9) f1(-18) f2(4) i(10) f1(-12) f2(6) i(11) f1(-9) f2(8) <------ When all of … | |
Re: You forgot to put the RefEnv:: infront of the two functions get_var and get_func. std::map<std::string, VarIdent>::iterator RefEnv::get_var(std::string s){ std::map<std::string, FuncIdent>::iterator RefEnv::get_func(std::string s){ And you have the wrong type for the second map template para. bool RefEnv::insert_func(Type t, std::string key, std::string n){ //Precondition: // A RefEnv object exists // //Postcondition: // … | |
Re: ##Try, but only tested it a little #include <vector> #include <iostream> using namespace std; int main(){ vector<int> m1,m2,m3; m1.push_back(0); m1.push_back(1); m1.push_back(1); m1.push_back(0); m1.push_back(0); m1.push_back(1); m1.push_back(1); m1.push_back(1); m1.push_back(1); m1.push_back(0); m1.push_back(1); m1.push_back(1); m1.push_back(0); m1.push_back(0); m1.push_back(0); m1.push_back(1); m2.push_back(0); m2.push_back(1); m2.push_back(0); m2.push_back(1); //------------------------------------------ // Just thinking // 1 2 3 4 5 6 // … | |
Re: Not at home to check it out but I pretty sure that your problem is, you are returning a pointer to something on the stack. ScoreEntry** retEntry = &newEntry; return retEntry; newEntry is a local variable and when you leave the Load function its address is no longer valid. Why … |