Search:

Type: Posts; User: Richardcavell

Page 1 of 6 1 2 3 4

Search: Search took 0.01 seconds.

  1. Replies
    2
    Views
    2,768

    How do I overload ostream::operator

    Hi, everyone. This code compiles and runs, producing the expected output:


    #include <iostream>

    template<typename T, std::size_t n>
    std::ostream& operator<<(std::ostream& os, const T...
  2. How do I read this source code out loud?

    Hi everyone. I teach myself from books and so sometimes I don't know how to communicate verbally.


    template<typename T>
    int fn(T a) {}

    How would you read that out loud to a co-worker? My...
  3. Replies
    1
    Views
    2,098

    How do I read this out loud?

    Hi everyone. I teach myself C++ using books and so I sometimes don't know how to read source code out loud. How would you pronounce this out loud?


    int &b = a;

    My best guess is:
    "Declare b...
  4. How do I overload the new operator to accept a std::string parameter?

    Hello. I'm a C++ newbie.

    I'm trying to do something very brave and beyond my capability.

    The code should explain what I'm trying to do. How would I overload the "new" operator so as to allow a...
  5. Can I sum a std::vector at compile time?

    Hi everyone. I have adapted this from page 9 of "A Tour of C++". I can't seem to sum the values in a std::vector<double> at compile time. Is it possible?


    #include <iostream>
    #include <vector>
    ...
  6. What about this? #include ...

    What about this?


    #include <iostream>

    class Foo {
    public:
    Foo() : x {} {}
    Foo(int n) : x {n} {}
    Foo(const Foo& rhs) {
  7. Argument passing vs copy initialization

    Hi. On page 4 of "A Tour of C++", Bjarne Stroustrup writes:



    I'm not sure that I fully understand this. Is there some example code that will demonstrate this? Is it possible to "trap" any copy...
  8. Replies
    3
    Views
    1,988

    Project/code review requested

    Good morning, gentlemen and ladies.

    I have written a small project in the C89 dialect of C. I am requesting a sizeable code review - in fact a review of the entire project - for anyone intrepid...
  9. Replies
    2
    Views
    6,232

    Making a const char * out of argv

    Hello, everyone. Here is the barebones of my code. I am trying to iterate the strings pointed to by argv, to parse options etc. My code never modifies the argv array, nor the strings pointed to by...
  10. Do I have to override functions in a base class?

    Hello, everyone. I'm trying to get my head around overriding functions of a base class, in C++. In this code:


    class Base {
    public:
    Base() {}
    virtual ~Base() {}

    virtual...
  11. Replies
    4
    Views
    4,173

    Hi, Jim. This is what I think are the operations...

    Hi, Jim. This is what I think are the operations generated.


    1. int i = 0;
    int j(0); // int constructor, given a parameter of 0
    int i(j); // int copy constructor, given a reference...
  12. Replies
    4
    Views
    4,173

    Constructors and assignment

    Hello, everyone. I'm learning C++ after coming from a C background. C++ does my head in by complicating things that in C can be assumed to be simple! Could someone please clarify for me *exactly*...
  13. Replies
    1
    Views
    2,135

    Namespaces - which function to call?

    Hello everyone.

    In the following code, a statement calls function sqrt(), when there are two functions called sqrt(). Is there a rule of "Assume the programmer means the one in the same namespace...
  14. Replies
    8
    Views
    3,342

    What should I study next?

    Hello.

    I'm a 39 year old man from the northwest of England, self-trained in computer programming. I'm trying to learn C++.

    So far, I've read the first 3 chapters of "A Tour of C++". I'm...
  15. Replies
    5
    Views
    4,043

    assert() in C++

    Hi, all. I'm watching a CPPCon 2016 video by Patrice Roy, in which he uses the code:


    assert(denom && "divide by zero");

    1. This is the same assert() function that is provided by the C...
  16. Replies
    2
    Views
    2,749

    Requesting feedback on my code

    Hello, everyone. I am a self-taught C programmer. I have written part of a word-wrapping program, about 300 lines so far in multiple files. I am requesting feedback about my coding style. I would...
  17. Replies
    6
    Views
    3,501

    Poll: Thanks all

    I agree that the buffer is unnecessary. Thanks for picking me up on that, and to all who replied. But your code is broken, algorism. Try doing "$replace run walk" with input of "overrun".
  18. Replies
    6
    Views
    3,501

    Poll: Please rate my code

    Hello, everyone. I'm a self-taught C programmer and I'm trying to learn to write code as professionally as possible. This program works, but could you give me a rating as to how well-written it is? ...
  19. Replies
    16
    Views
    2,814

    Gee, I thought it was pretty good. Thanks for...

    Gee, I thought it was pretty good. Thanks for everyone's feedback.

    Also, on the subject of changing the number to a positive number and then working on it, that doesn't work if the negative range...
  20. Replies
    16
    Views
    2,814

    Please rate at my code

    Hi everyone,

    I just want to get feedback on this code. I've been studying C seriously for a couple of years now, using K&R. Any comments?



    /* exercise 3-4 from K&R 2

    Write a version...
  21. Correct

    Yes, on line 254. Well spotted.
  22. Is my word-wrapping algorithm too complex?

    Hi, everyone.

    I am writing a word-wrapping program. The idea is that it will read in text, and ensure that no output line is longer than a given limit. Where a line of text contains at least one...
  23. Replies
    3
    Views
    1,492

    A few questions

    1. The standard allows multibyte character sets. What character set is most commonly used with C? Is it UTF-8?

    2. Does anyone actually use trigraphs these days? Or does that only apply to...
  24. Difference between freestanding and hosted implementations

    Hi, everyone.

    It occurs to me that when I am programming on, say OSX with gcc, the operating system designers and gcc writers between them have given me certain means of input and output. For...
  25. Replies
    3
    Views
    3,671

    Linker answer

    What about this?

    A linker is a computer program that takes one or more object files and creates an executable program. These object files might represent the output of the compiler from...
Results 1 to 25 of 145
Page 1 of 6 1 2 3 4