some small problems

1. pure virtual:
1
2
3
4
5
6
7
//  base class Worker, class Waiter, Singer
Waiter w_temp;
Singer s_temp;

Worker* pw[] = {&w_temp, &s_temp };
pw->Show(); // assume Show() is a virtual function, and Waiter and Singer class overrides it.
// Worker is a pure virtual function? can't instanciate, upper is not an instance, why not? 


2.about exception:
 
//if I throw a error like [code]throw "justSomeStirng."; 

catch(const char* s) // parameter must const, why?
[/code]


3.about vector:
1
2
std::vector<int> a;
std::cin >> a.at(i);  // is this right? why? 

 
Is there some member funcion for vector to acquire it's sum for vector<int>? 



4. why some code use the 2 versions? can't just the first version(It's also works for const object)?
1
2
double operator[](int i)const;
double& operator[](int i);

why can't use like this :
1
2
double& operator[](int i)const;
// is this for ensure the object can't change by other things? 




5. format
1
2
int lim = (n < MONTHS) ? n : MONTHS;
// is the braces necessayr? 
Last edited on
1 no idea what your worker function looks like
2 no idea what you are throwing
3 no, but you can use a for loop
4 const after a function tells the compiler that your function won't modify any private variables of the class
5 i would leave them to increase readability. If they are necessary: just try it?
Last edited on
Topic archived. No new replies allowed.