Sams Teach Yourself Visual C++ 6 in 24 Hours... Not working out :(

BigToque

Lifer
Oct 10, 1999
11,700
0
76
About a year ago, I bought a Visual C++ starter kit. It has a learners edition of VC++6. Anyway, I'm on hour 3 (just started last night), and this hour talks about functions, classes and structures.

Their example for classes doesnt make any sense to me. If I upload my .CPP file, could someone take a look at it and try to help me understand whats happening?

Any help is GREATLY appreciated.

here is is: WeeklyPay.CPP
 

Descartes

Lifer
Oct 10, 1999
13,968
2
0
What would you like to know about it?

That's a pretty basic example of a class, encapsulation, pointers, etc..

If you ask a more specific question, I'm sure someone will be willing to help.
 

BigToque

Lifer
Oct 10, 1999
11,700
0
76
ok, I see that in this example you assign 40.0 to dHours, and 3.75 to dRate. The program then outputs a message and says to get the salary from WeeklyPay.GetSalary().

The GetSalary() function says to multiply m_dHours and m_dRate to get the salary, and return that value to the main funtion.

What I dont understand is where the code tells the program to go to the functions that assign dHours and dRate to m_dHours and m_dRate.
 

FrogDog

Diamond Member
Jan 12, 2000
4,761
0
0
Stefan,

I bought that book a year ago as well. I hate it :|

So then a couple of months ago I bought Beggining Visual C++ 6 by Wrox publishing and I love it! :D

 

nd

Golden Member
Oct 9, 1999
1,690
0
0
I don't see what's so unclear. It's an extremely elementary example. The concept they're showing you here is that you hide your "private" data within the class so you don't directly access it. Instead of accessing m_dHours directly with weeklyPay.m_dHours (illegal), you use a function (member) that _DOES_ have access to it. This way, you have more control of how the outside world uses your class.

In this simple example, GetSalary() isn't assigning anything, it's just calculating the salary based on the two private variables.