![]() |
|
#1
|
|||
|
|||
Compiling with stubs for objectsWe need to compile our code using -Wall, and although the objects in the String class don't need to be complete, they need to be valid stubs, meaning they should still accept the right input, but just return zero.
" a) Your file must contain a syntactically valid function definition ("stub") for each of the functions you are required to implement for the project. " I'm curious though as how to declare these 'stubs' namely, the operators CPP / C++ / C Code:
These stubs I'm not so sure about... perhaps just returning zero? Also I had issues in constructing the String itself, We're not allowed to use anything from the string.h, cstring, and string directives. CPP / C++ / C Code:
and we have to do the same thing, but like CPP / C++ / C Code:
I know I'm somewhat close with the first one, but I'm not sure how to construct the strings ....The reason I'm posting this is when I go to compile I get the following error message ld: fatal: file /user/cse232/Projects/project07.check.o: wrong ELF machine type: EM_386 ld: fatal: File processing errors. No output written to a.out collect2: ld returned 1 exit status From what I've learned ELF machines means i'm unable to do something that normally the other machine can? Help is greatly appreciated, -Mr_Peepers |
|||
|
#2
|
|||
|
|||
Re: Compiling with stubs for objectsNo idea what u talkng here.
__________________
Linux is the best OS in the world. |
|
#3
|
|||
|
|||
Re: Compiling with stubs for objectsRegarding your 'stub' issue:
A stub usually refers to an empty definition of a function (therefore the requirement to be syntactically correct). So if you have the following declaration CPP / C++ / C Code:
CPP / C++ / C Code:
As far as the ELF problem you are having: It seems that you have compiled that file either on another machine or with a cross-compiler. In either case the binary does not match your system. You can simply delete the .o file and recompile the source files again. If you do not have access to the source then you can try to get to the target platform of that binary (possibly an ssh to another machine) or ask the person who generated the .o to recompile for your target platform. Realize that these are somewhat stabs in the dark as I do not know enough from what you provide to know for sure. Last edited by admin : 18-Mar-2008 at 04:42.
Reason: Please insert your example C/C++ codes between [CPP] and [/CPP] tags
|
|
#4
|
|||
|
|||
Re: Compiling with stubs for objectsthanks for the help on the stubs, I'm just not sure now as to how to construct these string objects
we have two ways to do it, one is by copying another string CPP / C++ / C Code:
and the other is in a c-style approach CPP / C++ / C Code:
our variables for type String are CPP / C++ / C Code:
I know mem is the array for the 'string' to be stored in, but what about constructing the string initially? I thought I might have had the right idea in my previous post |
|
#5
|
|||
|
|||
Re: Compiling with stubs for objectsYou can check the standard string library function and get idea how their implement this class.
I hope this help __________________
Linux is the best OS in the world. |
|
#6
|
|||
|
|||
Re: Compiling with stubs for objectsit seems to me that you have been given a class with the operations declared and you need to provide the definitions for that, yes? Given the following:
CPP / C++ / C Code:
CPP / C++ / C Code:
In either case though, you should always increase the buffer by a power of two when growing the capacity. (google 'amortized analysis accounting method' for details) So try and fill in each of those comment areas with the code that does what the comment says and post back with any problems. |
|
#7
|
|||
|
|||
Re: Compiling with stubs for objectsso when concatenating two of these Strings, if the capacity wouldn't hold both of them, would I create a new String object that holds both of them, or can one's capacity just be updated?
I guess logically I don't see how updating the capacity variable effects how much memory my Mem variable can hold. |
|
#8
|
|||
|
|||
Re: Compiling with stubs for objectsIt doesnt affect how much the buffer can hold, it details it. In other words, to implement the += operator you would do the following
CPP / C++ / C Code:
Essentially the capacity is the only way you know how much room is in the buffer. Without it, you would need to calculate the length of each string, allocate the new buffer, copy both strings to the new buffer, free the old buffers (if necessary) - every time you did the operation. That would be terribly wasteful and would defeat the purpose of wrapping the details in a class to begin with. |
|
#9
|
|||
|
|||
Re: Compiling with stubs for objectsso without getting down to the nitty gritty, it's something like this?
CPP / C++ / C Code:
also, without overloading the << operator, is there a way to print and test my constructors and the += operator? |
|
#10
|
|||
|
|||
Re: Compiling with stubs for objectsYou have the general idea. However, there is something in your comment that is not correct. It may be semantics but I believe it deserves a mention (I've added to your code my own explanation)
CPP / C++ / C Code:
CPP / C++ / C Code:
|
Recent GIDBlog
Non-US citizens serving in the military by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Help with C++ Compiling Error | Altmaniac | CPP / C++ Forum | 5 | 21-Aug-2007 06:29 |
| basic question regarding compiling a program | cornsnap | CPP / C++ Forum | 24 | 16-May-2007 14:08 |
| getting an error while compiling and running using different IDE. | jaro | C Programming Language | 0 | 25-Aug-2006 09:14 |
| issues compiling .h and .cpp files with Dev C++ | iceman2006 | CPP / C++ Forum | 9 | 17-May-2006 19:32 |
| C++ Compiling Error | pointer | MS Visual C++ / MFC Forum | 3 | 12-May-2005 04:08 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The