I vaguely remember that it is because we do not want any other things anyhow access that data accidentally or something like thatOriginally posted by LatecomerX:Me curious here, why is it a bad programming practice to declare such vars as public?
And to mayi: in the future, please spell my username as "LatecomerX', not with the "C" capitalized. A big "C" there looks...kinda weird.
C++ I got A+Originally posted by gigabyte14:java![]()
![]()
i got B, and i don't know how i got a B![]()
That piece of code is not Java, although concepts are the same.Originally posted by gigabyte14:java![]()
![]()
i got B, and i don't know how i got a B![]()
paiseh laOriginally posted by ndmmxiaomayi:That piece of code is not Java, although concepts are the same.
Oh. But use public accessor to get the var also can have accidents de ma.Originally posted by eagle:I vaguely remember that it is because we do not want any other things anyhow access that data accidentally or something like that
it's about information hiding and encapsulationOriginally posted by LatecomerX:Oh. But use public accessor to get the var also can have accidents de ma.
#include
void somefunction(object comOBJ);
void main()
{
COMPUTER comOBJ;
somefunction(comOBJ);
}
void somefunction(object comOBJ)
{
//some functionality
}
Originally posted by Xcert:Still on the subject of C++,anyone knows how to pass an object into a function as an input parameter?
assuming a class named COMPUTER is already defined...
something like the following(which obviously can't work)...
code:
#include
void somefunction(object comOBJ);
void main()
{
COMPUTER comOBJ;
somefunction(comOBJ);
}
void somefunction(object comOBJ)
{
//some functionality
}
#include
void somefunction(object comOBJ);
void main()
{
COMPUTER comOBJ;
somefunction(comOBJ);
}
void somefunction(COMPUTER comOBJ)
{
//some functionality
}
where are your header files for these 2 classes ? Will need to take a look at them to be sure.Originally posted by Xcert:code:
#include
#include
#include
#include
class employee
{
private:
int nSalary;
char name[80];
int nDept;
public:
void SetSalary(int);
void PrintSalary();
void SetName(char *aString);
protected:
};//end class employee
void employee::SetSalary(int s)
{
nSalary=s;
}//end void employee::SetSalary
void employee:: PrintSalary()
{
cout<<"nSalary of "<}//end void employee:: PrintSalary()
void employee::SetName(char *aString)
{
if(strlen(aString)<=79)
{
strcpy(name,aString);
}
else
{
strcpy(name, "Default" );
}
}//end void employee::SetName(char *aString)
class manager:public employee //Derived class
{
private:
int nOffice;
public:
void SetOffice(int);
void PrintOffice();
protected:
};//end class manager:public employee
void manager::SetOffice(int o)
{
nOffice=o;
}//end void manager::SetOffice(int o)
void manager:: PrintOffice()
{
cout<<"nOffice of "<}//end void manager:: PrintOffice()
anyone knows how can I print out the name of the manager in the last line.
Employee is the base class,manager is the derived class.
manager.name is obviously not correct.![]()
not really...I only know a bit of everything...started with Turbo C++...then VB6 for a project...then VC++(also project but foundation damn weak)...then the internet things like java,jsp,asp,applet,apache,IIS,PHP,mySQL,Oracle,etc...also know a bit of uP programming...now learning VC++ from scratch...at the same time need to come up with a windows device driver.I am so screwed.Originally posted by one-niner:where are your header files for these 2 classes ? Will need to take a look at them to be sure.
But as suggested by others on the thread.You will need to use accessor and mutator methods to explicty set and obtain the values you need.
Remember Strong Cohesion Loose Coupling.
Program with Performance in mind =)
I think you come from a java background right ? hence the different syntax and thought it can be achieved
accesor methods are used to obtain the values of object states. Another term used is getter methodOriginally posted by Xcert:not really...I only know a bit of everything...started with Turbo C++...then VB6 for a project...then VC++(also project but foundation damn weak)...then the internet things like java,jsp,asp,applet,apache,IIS,PHP,mySQL,Oracle,etc...also know a bit of uP programming...now learning VC++ from scratch...at the same time need to come up with a windows device driver.I am so screwed.
and ya...I guess U can say that my knowledge is pretty mixed up.
I understand the meaning of accessor...but what is a mutator method?function overloading?