Personal computing discussed

Moderators: renee, SecretSquirrel, just brew it!

 
ssidbroadcast
Graphmaster Gerbil
Topic Author
Posts: 1400
Joined: Sun Jul 08, 2007 10:42 pm
Location: Seattle, WA
Contact:

simple Obj - C help

Sun Sep 07, 2008 6:52 pm

hey guys,

As a personal training exercise I'm building a Calculator in xCode. Before I begin, here are the resouces:

YouTube Video 1: Building the interface
YouTube Video 2: Setting up the Outlets

Part 3: The source code, and a (better quality) Quicktime video explaining what it does.

All of my concerns are related to part 3, the programming part, but I put the first two parts for reference.

I had gone through the video step-by-step and reproduced the code by hand to the best of my ability, but as of now I have about 14 errors. That's down from about 27 errors, which is good I guess, but these last ones have me scratching my head. I've included the Regexkit.h file properly (I think) and done everything else as he has it laid out in the source code. I think all of my problems are in file CalcController.m and this is my first problem:

Image

I don't understand what the compiler wants. It's exactly as the source code laid out. syntax error?

Next:

Image

These errors are all in the math implementations (plus, subtract, divide, multiply) so there are four of them I think. Strictly:
- (IBAction)push_plus:    (id)sender {
   //Basically, if any of the other buttons are on, then turn this button off?
   if ([m_button state] == NSOnState || [s_button state] == NSOnState || [d_button state] == NSOnState);
       [a_button setState:NSOffState];
}
    else {
      [self check_calc_model];
      
      if (!calc_model.first_call)
         [self push_equal:0];
      
      calc_model.sign_state = 'a';
      [calc_model computeNewDisplayVal:[calc_display floatValue]];
      [calc_display setFloatValue:calc_model.running_total];
   }
}


Lastly, this is the most frustrating:

Image

Now I can sortof empathize with the error because that really *is* the first time calc_model shows up, but it's also (as far as I can tell) exactly as Chris M had coded it, so it *should* work, right?

Any pointers, tips, suggestions, etc. would be great.
2014 21" iMac w Intel Iris Pro
 
mortifiedPenguin
Gerbil Elite
Posts: 812
Joined: Mon Oct 08, 2007 7:46 pm

Re: simple Obj - C help

Mon Sep 08, 2008 12:41 am

The first error you have sounds like a problem in your header file. When importing a .h file, many C++ compilers use a preprocessor to essentially copy the contents of the .h file over into the .cpp. In short, check your header file for a mistake before "CalcModel."

Second error, there appears to be a semicolon in your if-statement (immediately after the closing paren) which destroys your if-else structure. Also, there is a curly brace after "[a_button setState:NSOffState]" which also messes up your function's structure. A good way of avoiding the curly brace issue is to try to always have your curly braces lined up and on lines of their own.

example:
public void foo()
{
    int boo;
}
// as opposed to
public void bar(){
    int boo;
}


ssidbroadcast wrote:
Now I can sortof empathize with the error because that really *is* the first time calc_model shows up, but it's also (as far as I can tell) exactly as Chris M had coded it, so it *should* work, right?
Like the compiler says, is calc_model actually declared? And if it has been is it in the right spot? For example, it could have been declared within another function when it should be global or perhaps you should have been passing the function a reference or pointer but the function doesn't have one as a parameter?

Hope this helps.

edit: fixed broken quote box
Last edited by mortifiedPenguin on Mon Sep 08, 2008 2:09 am, edited 1 time in total.
2600K @ 4.8GHz; XSPC Rasa/RX240/RX120 Phobya Xtreme 200; Asus P8Z68-V Pro; 16GB Corsair Vengeance 1333 C9; 2x7970 OC w/ Razor 7970; Force GT 120GB; 3x F3 1TB; Corsair HX750; X-Fi Titanium; Corsair Obsidian 650D; Dell 2408WFP Rev. A01; 2x Dell U2412m
 
ssidbroadcast
Graphmaster Gerbil
Topic Author
Posts: 1400
Joined: Sun Jul 08, 2007 10:42 pm
Location: Seattle, WA
Contact:

Re: simple Obj - C help

Mon Sep 08, 2008 1:05 am

Ha. I made some of those changes you suggested for the 2nd error, and my error count increased!. :) (from 14 to 18) However, they no longer whine about syntax. Rather, they are repeats of the 3rd error type: "error: 'calc_model' undeclared (first use in this function)"

and again a few lines later: "error: 'calc_display' undeclared (first use in this function)

So it seems if I fix this problem, then hopefully most of my problems will go away. I checked around and CalcController.h *does* define both calc_model and calc_display here:

@interface CalcController : NSObject {
    IBOutlet id calc_disp;
   IBOutlet id a_button;
    IBOutlet id d_button;
    IBOutlet id m_button;
    IBOutlet id s_button;
   CalcModel* calc_model;
}


Now, since I've imported CalcController.h at the top, shouldn't defined variables carry over? Isn't that one of several key purposes of importing?

Thanks again for the help!

Who is online

Users browsing this forum: No registered users and 1 guest
GZIP: On