Chapter 8 Drill 1

128 views
Skip to first unread message

Aiden

unread,
Mar 7, 2011, 11:00:11 AM3/7/11
to PPP-public
I understand what I need to do, but I'm having a bit of difficulty
grasping how to do it.
So far I really just put what it told me so I have my.cpp calling
"std_lib_facilities.h" and "my.h" and use.cpp calling "my.h", but I
really just don't know where to go from here.

Anyone have tips on where to go/what to do?

Aiden

unread,
Mar 20, 2011, 3:54:23 PM3/20/11
to PPP-public
Sorry if this is frowned upon, but I'm bumping this to try and get
help.

Jay x

unread,
Mar 20, 2011, 8:00:35 PM3/20/11
to ppp-p...@googlegroups.com
Are you getting an error message?

--
You received this message because you are subscribed to the Google Groups "PPP-public" group.
To post to this group, send email to ppp-p...@googlegroups.com.
To unsubscribe from this group, send email to ppp-public+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/ppp-public?hl=en.


Daniel Hogue

unread,
Mar 21, 2011, 1:32:27 AM3/21/11
to ppp-p...@googlegroups.com
No I just don't have anything to do yet. I don't know where to start really.

Jay x

unread,
Mar 21, 2011, 2:45:02 AM3/21/11
to ppp-p...@googlegroups.com
hmm well this is what I did:

my.h file contains two function prototypes and an extern decleration to bring foo into scope.
//------------------------------------ my.h ------------------------------------------
extern int foo;
void print_foo();
void print(int);
//------------------------------------ my.h ------------------------------------------

my.cpp contains the implementation of the functions print_foo() and print(int).
//------------------------------------ my.cpp ------------------------------------------
#include "std_lib_facilities.h"
#include "my.h"

void print_foo()
{
   cout << foo << endl;
}

void print(int i)
{
   cout << i << endl;
}
//------------------------------------ my.cpp ------------------------------------------

use.cpp will have the main method
//------------------------------------ use.cpp -----------------------------------------
#include "my.h"

int main()
{
   foo = 7;
   print_foo();
   print(99);
 
   return 0;
}
//------------------------------------ use.cpp -----------------------------------------

You also need to declare foo (int foo;) somewhere, I chose to declare it on the last line of std_lib_facilities.h and then removed it after I verified it compiles and runs.

If you're on linux you can use this command to compile and run: g++ my.cpp use.cpp -o drill_1 ; ./drill_1

Aiden

unread,
Mar 21, 2011, 10:06:30 AM3/21/11
to PPP-public
Oh.. ok, I thought we couldn't use std_lib_facilities or anything like
that, haha I was so confused.

Thanks.
> On Mon, Mar 21, 2011 at 1:32 AM, Daniel Hogue <daniel.e.hog...@gmail.com>wrote:
>
>
>
> > No I just don't have anything to do yet. I don't know where to start
> > really.
>
> > On Sun, Mar 20, 2011 at 7:00 PM, Jay x <jaydo...@gmail.com> wrote:
>
> >> Are you getting an error message?
>
> >http://groups.google.com/group/ppp-public?hl=en.- Hide quoted text -
>
> - Show quoted text -

Aiden

unread,
Mar 21, 2011, 10:53:43 AM3/21/11
to PPP-public
Wow, I feel dumb, I didn't even notice that it said to include that.
Gah, well, that's my fault.
> > >http://groups.google.com/group/ppp-public?hl=en.-Hide quoted text -
>
> > - Show quoted text -- Hide quoted text -
Reply all
Reply to author
Forward
0 new messages