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...
Type: Posts; User: Richardcavell
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...
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...
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...
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...
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>
...
What about this?
#include <iostream>
class Foo {
public:
Foo() : x {} {}
Foo(int n) : x {n} {}
Foo(const Foo& rhs) {
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...
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...
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...
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...
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...
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*...
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...
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...
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...
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...
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".
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? ...
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...
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...
Yes, on line 254. Well spotted.
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...
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...
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...
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...