Mailinglist Archive: opensuse-programming (68 mails)

< Previous Next >
Re: [suse-programming-e] C++ compile problem. error in function
  • From: Trey Gruel <drathos-suse@xxxxxxxxxxxxxx>
  • Date: Mon, 12 Jan 2004 15:17:40 -0500 (EST)
  • Message-id: <Pine.LNX.4.44.0401121504050.28966-100000@xxxxxxxxxxxxxxxxxxxxx>
> I think that Trey's comments are legitimate, but not the solution.
> bill.stock is a single instance of a stock item.
> I think you might be able to cast this:
> bill.stock = *<static_cast<StockItem *>(&stock[item]);
>
> What you apparently want to do is to copy a single instance.
> Or you can use the memcpy function.

looking at the full code, i don't see why bill.stock is an array. the
only places it's used, it's always treated as a single instance. setting
it to a pointer as you describe is probably the most memory efficient, but
he would have to check in his delete_data function if the stock he's
deleting is referenced by bill. this seems to be a program for a
beginning level class and i'm not sure how far they've gotten. as such, i
would suggest copying the data instead of pointing to it.

> But, it appears that your code is really C being compiled with a C++
> compiler.

that's pretty much the way most colleges are teaching it nowadays. stuff
that could be taught in c (or even more simple langauges) all being taught
in c++ or java. as it is, he is using c++ iostream for is user io.

note: i didn't give a specific solution out of old habit. when i was a
ta, i found that most students remembered solutions better if they found
it themselves. because of that i tended to only help them find the
problem and set them loose to find the solution. if they were still
having trouble, i'd give them a nudge or two in the right direction, but
would never simply give the solution to the problem at hand.

--
trey


< Previous Next >
References