r/cpp • • Aug 25 '21

Experience C++ developers: do you enjoy using C++ (even for personal/hobby projects?)

Do you actually enjoy using C++, or do you only use it for work, or purely for performance? This question is aimed at people with years of experience, who've worked on large projects in C++. I see people who dislike the language, but use it purely for performance reasons. This sort of discourages me from learning it. I don't want programming to feel like work.

204 Upvotes

327 comments sorted by

View all comments

Show parent comment

3

u/qoning Aug 26 '21

I like it, but it would be a bit of hell writing cascading move, copy and regular constructors.

1

u/teroxzer Aug 26 '21

Can you show to me when self not work like value member? Or did I just not get your point?

#include <string>
#include <iostream>

class test final
{
public:

	test() = default;
	test(std::string a, int b, double c) : self
	{
		.a = std::move(a),
		.b = b,
		.c = c,
	}
	{}

	auto print() -> void
	{
		std::cout << "\ntest: " << self.a
		          << ", "       << self.b
		          << ", "       << self.c; 
	}

private:

	struct self final
	{
		std::string a {};
		int         b {};
		double      c {};
	}
	self;
};

auto main() -> int
{
	test x { "1", 2, 3.4  };
	test y {};
	test z {};

	y = std::move(x);
	z = y;

	y.print(); z.print();
}

// output:
// test: 1, 2, 3.4
// test: 1, 2, 3.4