No one has voted on any posts yet. Votes from other community members are used to determine a member's reputation amongst their peers.
[CODE]#include "stdafx.h" #include<iostream> using namespace std; class A { public: A(){} void setdata(int s) {t=s;} int getdata(){return t;} protected: int t; }; class B: public A { public: B(){} }; void main() { A a; a.setdata(3); B b; cout<<b.getdata(); }[/CODE] Why I cannot get an output of 3 here? Can … |
|
I got run-time error for the following code. I am just starting to get familiar with linked list. Can any one point out what's the problem here? thanks [CODE] #include "stdafx.h" #include<iostream> using namespace std; struct node { int data; node * next; }; node* buildonetwothree() { node* head=NULL; node* … |
|
I got run-time error in the following simple code, but I don't know what's the problem. can any one help? [CODE] #include "stdafx.h" #include<iostream> using namespace std; void reverse (char * source) { int i=0, j=strlen(source)-1; while (i<j) {char temp=source[j]; source[j]=source[i]; source[i]=temp; i++; j--; } cout<<source<<endl; } void main() { … |
|
say iter1 and iter2 are both iterators [CODE]*iter1++=*iter2++;[/CODE] what does this line means? Can anybody help explain? ++ and * which is done first? thanks |
|
I am not familiar with Java, but I have a question about a Java code which is supposed to find the first non-repeat element in an array. [CODE] Hashtable<Integer, Boolean> positions = new Hashtable<Integer,Boolean>(); int[] elements = {2, 2, 4, 5, 1, 6, 0, 9, 1, 4, 5, 10}; for(int … |
|
[CODE]// pointers to base class #include <iostream> using namespace std; class CPolygon { protected: int width, height; public: void set_values (int a, int b) { width=a; height=b; } }; class CRectangle: public CPolygon { public: int area () { return (width * height); } }; class CTriangle: public CPolygon { … |
|
[CODE]a= a >0 ? a : 0;[/CODE] what does this mean? thanks |
|
[CODE]Class date{ protected: int year_; int month_; int day_; public: date(); date(const int& d, const int& m, const int& y); date operator++(); //prefix operator date operator++(int); //postfix operator date operator--(); //prefix operator date operator--(int); //postfix operator }; date date::operator++(int){ //postfix operator return current value date d=*this; *this=next_date(d); return d; } … |
|
If I declared a static variable in a header file, and the header file is included in a couple of .c files. Is there any problem? Thanks |
|
If I declared a static variable in a header file, and the header file is included in a couple of .c files. Is there any problem? Thanks |
|
|
|
I am not familiar with linked list, can any one help? |
|
1. an int and a class with only an int member, are they of the same size? 2. what is the size of a class containing 4 ints and a virtual function? |
|
In the following code, why x=new int; y=new int; are a must, if I comment out these two then I will have run-time error. I think I have int * x; and int* y; already shows that x and y are pointers point to int. There is no need to … |
|
I saw the following sentences from a book “A difference between a destructor and other member functions is that, if a regular member function has a body at the derived class, only the version at Derived class gets executed. Whereas in case of destructors, both derived as well as base … |
|
I am not quite sure if I understand the meaning of the question very well I am thinking the answer is yes since we can use dynamic binding? Is this the right answer? Thanks |
|
in c++ primer " [CODE]void reset(int *ip) { *ip = 0; ip = 0; }[/CODE] After a call to reset, the argument is unchanged but the object to which the argument points will be 0:" I understand that the argument is unchanged, but why the object to which the argument … |
|
In the following program, why there is no delete in the destructor? is it because there is no pointer involved, so no memory needs to be released? How about the memory allocated when constructing M,P,S,N, the memory will be release automatically when the program ends? Thanks [CODE]#include<iostream.h> class point { … |
|
In this class, line 3 "char * pName" and last line "char * name" pName and name are pointers or strings? I think they are pointers but if they are pointers how can we do strlen(pName) and strcpy(name,pName) in the code? Thanks class student { public: student(char * pName="no name",int … |
|
Struct Day { explicit Day(int d) : val(d) {} int val; }; what does the colon in the 3rd line means? Thanks |
|
[code] class TextBlock { pulic: ... const char& operator[] (std:size_t position) const {return text[position];} char& operator[] (std:size_t position) {return text[position];} private: std::string text; }; [/code] for the member functions why the return type is reference to char char& instead of char? return text[position] is a char for sure,not an address, … |