
C++ Problem Solving
GetRekt
这个作者很懒,什么都没留下…
展开
-
C++ 长行字符串多行书写
问题在使用C++编写图形学程序的时候往往会碰到需要将着色器代码变为字符串嵌入代码的情况。如何将着色器代码更简便快捷的用字符串表示出来便成为了一个问题。解决方案使用双引号string testShader = "uniform mat4 g_mvpMatrix; \n" "attribute vec3 position;\n" ...原创 2019-08-26 17:18:04 · 12879 阅读 · 2 评论 -
Initialize Member Variable Which is an Object
ProblemI have a class with a member as an object of another class. I want to initialize it and use it.class Test {public: TestImpl testImpl;}SolutionUse Guaranteed Initialization (Suggested)c...原创 2019-08-27 21:06:20 · 206 阅读 · 0 评论 -
C++ 中多余大括号的用处
问题今天看同事代码的时候见到了一种比较特殊的c++写法。bool test(){ ... \\ Some unrelated code { \\ Some other code ... } \\ Somce unrelated code ...}在代码中有一个多余的大括号,但是不知道是做什么用的,因为他不和前面或后面的任何代码有关。解释这个多余的大括号提供了一个...原创 2019-08-28 18:23:34 · 1530 阅读 · 1 评论 -
Forward Declare an Enum (error: ISO C++ forbids forward references to 'enum' types)
注: 此为英文笔记,如需翻译请私信或留评论To declare an Enum, this way won’t work. The compiler will throw a compile error since no size is explicitly specified.enum e;void Foo (E e);enum E {A, B, C};Instead, in C...原创 2019-08-28 19:14:10 · 4777 阅读 · 0 评论 -
C++隐式转换与explicit关键字
隐式转换定义Implicit conversions are performed whenever an expression of some type T1 is used in context that does not accept that type, but accepts some other type T2; in particular:when the expression ...原创 2019-08-29 12:14:25 · 323 阅读 · 0 评论 -
How to store data that can be used by another class?
ProblemBased on the One Responsibility Principle, we usually want the data as a separate component from the implementation class. This implys an “is implemented in terms of” relationship.Implement t...原创 2019-09-03 20:55:49 · 179 阅读 · 0 评论