小编t3h*_*iel的帖子

用花括号C++实例化一个Object

我已经阅读了许多关于使用大括号初始化的解释:

PhoneNumber homePhone = {858, 555, 1234};
Run Code Online (Sandbox Code Playgroud)

以及

int x2 = val; // if val==7.9, x2 becomes 7 (bad)

char c2 = val2; // if val2==1025, c2 becomes 1 (bad)

int x3 {val}; // error: possible truncation (good)

char c3 {val2}; // error: possible narrowing (good)

char c4 {24}; // OK: 24 can be represented exactly as a char (good)

char c5 {264}; // error (assuming 8-bit chars): 264 cannot be 
               // represented as a char (good)
Run Code Online (Sandbox Code Playgroud)

但是,我在这里遇到一些代码,我找不到一个例子,也许我不知道这个术语,所以我可以google它:

auto ac1 …
Run Code Online (Sandbox Code Playgroud)

c++ initialization object

7
推荐指数
2
解决办法
3544
查看次数

增加RGB亮度的公式?

快速提问!

我有一个 RGB 值,我想进行转换以将其亮度提高 50%。我找到了一个伽马公式,但我不确定伽马是否是正确的方法。

到目前为止,我正在使用:

        r = 255*((R/255.0)^ (1/1.5));
        g = 255*((G/255.0)^ (1/1.5));
        b = 255*((B/255.0)^ (1/1.5));
Run Code Online (Sandbox Code Playgroud)

我所做的就是将伽马乘以 1.5。图像确实看起来更亮了,但我不确定它是否真的亮了 50% 或者我使用的公式是否错误。这样对吗?

rgb image gamma

6
推荐指数
1
解决办法
7531
查看次数

C++ 深度复制链表

首先,这是我目前正在尝试解决的任务的一部分。我正在尝试创建一个复制构造函数来深度复制给定的 LinkedList。我已经对 LinkedList 方法进行了编码。

这是 LinkedList.h 文件的必要部分。

LinkedList.h
private:
    struct node {
        Val data;
        node* next = nullptr;

    };

    typedef struct node* nodePtr;


    nodePtr head = nullptr;
    nodePtr current = nullptr;
    nodePtr temp = nullptr;
};
Run Code Online (Sandbox Code Playgroud)

参数给出: "LinkedList::LinkedList(const LinkedList & ll)" ll 是要复制的链表。我首先测试链表中是否有头,如果没有,则表示链表为空。然后我将旧列表中的头部复制到新列表中。然后我将新电流设置到头部以准备 while 循环。在 while 循环中,我正在复制当前节点的数据以及指向下一个节点的指针。最后,我将下一个指针设置为 nullptr 以表示新列表的结尾。

LinkedList.cpp

LinkedList::LinkedList(const LinkedList & ll){
    if (ll.head == nullptr) {
        return;
    }
    head = ll.head;
    current = head;


    while (ll.current->next != nullptr) {
        current->data = ll.current->data;
        current->next = ll.current->next;
    }
    current->next …
Run Code Online (Sandbox Code Playgroud)

c++ struct linked-list

4
推荐指数
1
解决办法
2万
查看次数

cout 和字符串连接

我只是在复习我的 C++。我试图这样做:

#include <iostream>

using std::cout;
using std::endl;

void printStuff(int x);

int main() {
    printStuff(10);
    return 0;
}

void printStuff(int x) {
    cout << "My favorite number is " + x << endl;
}
Run Code Online (Sandbox Code Playgroud)

问题发生在printStuff函数中。当我运行它时,输出中省略了“我最喜欢的数字是”中的前 10 个字符。输出是“e number is”。这个数字甚至没有出现。

解决这个问题的方法是做

void printStuff(int x) {
    cout << "My favorite number is " << x << endl;
}
Run Code Online (Sandbox Code Playgroud)

我想知道计算机/编译器在幕后做什么。

c++ iostream string-concatenation

3
推荐指数
2
解决办法
2万
查看次数