24 Discussion / Question Topics
Remove Filter Hi Guys, I am trying to teach myself templates and I keep getting lost in all these compilation errors. Here is the latest // This is the interface for the base class template<class V, class I =int> class Array{ private: vector<V> myStore; public: Array(); Array(I size); Array(I size, V value); … | |
Hi Guys, I am trying to teach myself templates in C++. My current assignment is to create a matrix class by using vector of vectors. I have got most of it done but my code is crashing when I try to overload the random access operator in my matrix class. … | |
Hi everybody, Please excuse the noob question as I am new to STL in C++. I am trying to write a very basic program which uses iota. However my compiler is complaining that iota does not exist in algorithm. Some other forums suggested including <backward/algo.h> as iota could have been … | |
Hi Folks, Here is another noob question. I am trying to write a simple predicate for the find_if function in STL. Here is my code #include<iostream> #include<vector> #include<algorithm> #include<iterator> using namespace std; class InRange{ const int& low; const int& high; public: InRange(const int& l, const int& h): low(l), high(h){} bool … | |
Hello everybody, I am trying to teach my stl and after writing some basic programs I have hit a road block. I have an iterator which I am trying to pass to a function template Here is my function template template <class T> void display(typename vector<T>::iterator start, typename vector<T>::iterator end){ … | |
Hello Everybody, I was recently looking some code ... The person who wrote the code was using the ping command to send some data to the google.com and then he recovered some statistics from mdev ... [URL="http://www.daniweb.com/software-development/cpp/threads/360576/1542507#post1542507"]This[/URL] link contains the source code I am referring to ... My question is … | |
Hello Everybody, I am on a Ubuntu system and I just came across /dev/random I tried searching for examples of how to use this utility (or file/ or command) to generate a random number but I cannot find anything. Quick note I am trying to generate a random number on … | |
Hi All, First of all let me start by saying I love Daniweb and I try to take time out everyday to answer the questions that are posted in the various forums. But I am often on the move which means I have to follow the chains of messages in … | |
Hello Everybody, I have a small confusion with regards to pointers. Here is some code [CODE] int main() { int *p1 = (int*)malloc(sizeof(int)); *p1 = 10; printf("The number is %d",*(char*)p1); }[/CODE] I run the code and the O/p is 10. My question is, is there no difference in using char … | |
Hello Everybody, I have a small doubt regarding how we can call constructors in a C++ class [CODE]class test { public: test() { cout<<"In test\n"; } }; int main() { test t1; test t2(); // This call does not give compile time error but does not call the constructor cin.get(); … | |
Hello people I have a small doubt in operator overloading I am trying to overload the assignment operator. Here is my code for that [CODE] class rational { int x; int y; public: //All the constructos rational operator= (rational num) { // Why do we need to return a reference … | |
Hello Everybody, Most of my coding experience is in C. Although I have a background in C++, I know very little of STL and the advanced topics in C++. I came across this code [code=c++] struct g { g():n(0) { } int operator()() { return n++; } int n; }; … | |
Hello People, I just came across this code as I was browsing through some C++ problem sets. This code gives compile time error but I am unable to understand the reason. I am C guy and my knowledge about C++ is not that great. So pardon if there is an … | |
Hello People, I cannot understand how this expression gets evaluated .. 1+~0 From what I know ~ has higher priority . So the expression becomes 1+(~0)= 2 But the answer that I got was 0. I know it is some thing to do with the fact that ~ is right … | |
Hello People... I found this sample code online [code=c ] int main(int argc, char* argv[]) { struct bitfield { signed int a:3; unsigned int b:13; unsigned int c:1; }; struct bitfield bit1={2,14,1}; printf("%d",sizeof(bit1)); return 1; } [/code] I compiled this code on linux with gcc compiler and the output I … | |
[code=c] int main(int argc, char* argv[]) { int a=3,b=2,c; a=a==b==0; printf("%d\n",a); return 1; } [/code] I cannot understand why this code gives 1 as the answer. According to me , this should be the order of evaluation b==0, which gives false & the expression becomes a=a==0 this should again give … | |
Hi All, Today I came across a peculiar piece of code. [code] int main(int argc, char* argv[]) { printf("%lf\n",(0.99-0.90-0.09)); } [/code] According to me the output for this code should be 0, but to my surprise when I ran this code the answer that I got was -0.000. I cannot … | |
Hello People, Does any one have any practice problem sets for C. I am interviewing for a company tomorrow and they ask lots of "Whats the output ?" kind of questions.. Any help would be appreciated | |
Hello Everybody, I have just come across this particular piece of code in a C problem set [code= c] main() { int i=5,j=6,z; printf("%d",i+++j); } [/code] The answer for this question is 11 because C evaluates this as i++ +j. But why cant this be evaluated as i+ ++j. Is … | |
Is there any standard rules when we write the main function. I always thought the main function should always be written as [code=c] int main(int argc, char* argv) { ..... return 1; } [/code] But to my surprise, all these definitions are also correct . I got a compile time … | |
Hello All, I am unable to understand this piece of code [code= c] main() { int i, j; scanf("%d %d"+scanf("%d %d", &i, &j)); printf("%d %d", i, j); } [/code] I got this question from a C problem set. I run this code and I have to give the i/p 3 … | |
Hello, I have a conceptual code related to the C memory allocation model if I have some code of this form, I will get a seg fault [code=c] int main() { char* p; *(p+5)='A'; printf("%c\n",*(p+5)); } [/code] But when I have some code of this form I do not get … | |
Hello, [code= c] main() { int i=4,j=7; j = j || i++ && printf("YOU CAN"); printf("%d %d", i, j); } [/code] The answer to this question is 4 1 and the reasoning is that the compiler finds j to be true and hence does not need to check the remaining … | |
[code=c] union u { union u { int i; int j; }a[10]; int b[10]; }u; main() { printf("n%d", sizeof(u)); printf(" %d", sizeof(u.a)); printf("%d", sizeof(u.a[4].i)); } [/code] Hello People. I just came across this piece of C code. I have a couple of question The third printf statement gives me the … |
The End.