|
|
|
|
"Terminate called after throwing an instance of 'std::logic_error' what(): basic_string::_S_construct null not valid Have 2 arguments: /home/jacky/Dropbox/eclipse-workspace/assignment-4f/Debug/assignment-4f /home/jacky/Dropbox/eclipse-workspace/assignment-4f/src/testio.dat Test: lines1 |
|
|
|
|
new without delete . Avoid new & delete whenever you can - investigate smart pointers instead.std::vector rather than arrays.| BarelyOtaku wrote: | ||
|---|---|---|
|
| http://en.cppreference.com/w/cpp/language/template_specialization |
static_assert and type traits, although this is only a compile time checking facility:| http://en.cppreference.com/w/cpp/language/static_assert |
| http://www.cplusplus.com/forum/lounge/111518/#msg608851 |
std::string with 1 char in it, instead of a char . In this case you could just cast it to a char anyway, but if it has multiple chars, throw the exception.std::string that throws, not sure on that though, I haven't tried it. |
|
ProcessData function. Make use of a union, seen as the types are known and there is only 1 of them at a time - you could have a std::vector of the union type. A union is similar to a class or struct - they can have constructors and everything - but there are restrictions as it can only hold 1 type of data at a time.| http://en.cppreference.com/w/cpp/language/union |
|
|
|
|
Have 2 arguments: /home/jacky/Dropbox/eclipse-workspace/assignment-4f/Debug/assignment-4f /home/jacky/Dropbox/eclipse-workspace/assignment-4f/src/testio.dat test123123Test: lines01 |
| And I have no idea how to use the Debugger so I can't give feedback about it D: |
|
|
|
|
std::vector of struct with a union inside - you could avoid the getlines function (just determines number of lines in file) altogether, and simplify the code in other ways: |
|
| http://en.cppreference.com/w/cpp/language/union |
ReadAndWrite function, use std::vector instead of pointers and arrays (remove the need for getlines function), use smart pointers instead of allocating on the stack or using new .struct with the union along with a vector to store them, things will be much easier & efficient IMO. Maybe this is why your prof said there was no need to use templates. On the other hand it is good to have a go at using them.readAndWrite() by breaking it into three functions and then grouping them up under the readAndWrite() function (which is now called processData()).| Whatever I'll try it I just hope she doesn't accuse me of plagiarism XD |
| - Do I declare struct in a data.h along with other functions? Or would I need a new file? |
| - You mentioned I need a constructor so would I basically implement and initialize a struct the same way I do with a class? |
struct is the same as a class in every respect, except the default access is public: It's handy when the struct will be a type stored in a container, so one doesn't have to bother with accessor functions for the struct.| - I need to use the try and catch method, would I implement this in the main or struct file? |
throw whenever a class invariant is violated. An invariant is a value of a member variable that must make sense for the class to operate correctly. For example a someone's age must be positive.try anything that is going to change a member value. So this includes upon (technically before) construction. Use function try block in the initialiser list to catch broad errors like when the input is negative when unsigned is expected. Create your own exception types to test valid ranges say for Longitude is 0.0 to 180.0 . This way all the member values are validated before the object is created, and creation doesn't happen at all if any of them throw. The try catch part is in the code that creates a new object.throw whenever a member value might change and be invalid during runtime - so this will be in the member functions, the try and catch part will be where the function are called from.| the assignment specified "a" function to read, reverse and write the sequence |
ReadReverseWriteData external to any class, in the scope of main() - it can call the objects functions.
|
|
|
|
|
|
union Type gets errors saying "from this location". I'm guessing the problem is that dSize isn't initialized which causes an error with the arrays.
FileRecord class will contain the Type, number of, and a vector of the union which are the actual values. The class will have the 3 functions mentioned earlier. Then on top of that there will be a vector of the FileRecords to store all the data in the file.