Search Results

Search found 5 results on 1 pages for 'maxpm'.

Page 1/1 | 1 

  • Interpreting Others' Source Code

    - by Maxpm
    Note: I am aware of this question. This question is a bit more specific and in-depth, however, focusing on reading the actual code rather than debugging it or asking the author. As a student in an introductory-level computer science class, my friends occasionally ask me to help them with their assignments. Programming is something I'm very proud of, so I'm always happy to oblige. However, I usually have difficulty interpreting their source code. Sometimes this is due to a strange or inconsistent style, sometimes it's due to strange design requirements specified in the assignment, and sometimes it's just due to my stupidity. In any case, I end up looking like an idiot staring at the screen for several minutes saying "Uh..." I usually check for the common errors first - missing semicolons or parentheses, using commas instead of extractor operators, etc. The trouble comes when that fails. I often can't step through with a debugger because it's a syntax error, and I often can't ask the author because he/she him/herself doesn't understand the design decisions. How do you typically read the source code of others? Do you read through the code from top-down, or do you follow each function as it's called? How do you know when to say "It's time to refactor?"

    Read the article

  • Commenting/In-Code Documentation Styles

    - by Maxpm
    This might be a stupid question, but it's been in the back of my head for a while and I can't find a decent answer anywhere else. I have a teacher who says we should explicitly list each parameter with a description, even if there's only one. This leads to a lot of repetition: double MyFunction(const int MyParam); // Function: MyFunction // Summary: Does stuff with MyParam. // Input: int MyParam - The number to do stuff with. // Output: MyParam with stuff done to it. When writing in-code documentation, how detailed are you?

    Read the article

  • Class Assignment Operators

    - by Maxpm
    I made the following operator overloading test: #include <iostream> #include <string> using namespace std; class TestClass { string ClassName; public: TestClass(string Name) { ClassName = Name; cout << ClassName << " constructed." << endl; } ~TestClass() { cout << ClassName << " destructed." << endl; } void operator=(TestClass Other) { cout << ClassName << " in operator=" << endl; cout << "The address of the other class is " << &Other << "." << endl; } }; int main() { TestClass FirstInstance("FirstInstance"); TestClass SecondInstance("SecondInstance"); FirstInstance = SecondInstance; SecondInstance = FirstInstance; return 0; } The assignment operator behaves as-expected, outputting the address of the other class. Now, how would I actually assign something from the other class? For example, something like this: void operator=(TestClass Other) { ClassName = Other.ClassName; }

    Read the article

  • Compilation Error on Recursive Variadic Template Function

    - by Maxpm
    I've prepared a simple variadic template test in Code::Blocks, but I'm getting an error: No matching function for call to 'OutputSizes()' Here's my source code: #include <iostream> #include <typeinfo> using namespace std; template <typename FirstDatatype, typename... DatatypeList> void OutputSizes() { std::cout << typeid(FirstDatatype).name() << ": " << sizeof(FirstDatatype) << std::endl; OutputSizes<DatatypeList...>(); } int main() { OutputSizes<char, int, long int>(); return 0; } I'm using GNU GCC with -std=C++0x. Using std=gnu++0x makes no difference.

    Read the article

  • Multiple-File Template Implementation

    - by Maxpm
    With normal functions, the declaration and definition are often separated across multiple files like so: // Foo.h namespace Foo { void Bar(); } . // Foo.cpp #include "Foo.h" void Foo::Bar() { cout << "Inside function." << endl; } It is my understanding that this cannot be done with templates. The declaration and definition must not be separate because the appropriate form of the template is created "on-demand" when needed. So, how and where are templates typically defined in a multiple-file project like this? My intuition is that it would be in Foo.cpp because that's where the "meat" of functions normally is, but on the other hand it's the header file that's going to be included.

    Read the article

1