鍍金池/ 問答/ C++問答
命于你 回答

judge并沒有立即執(zhí)行,而是在(...arg)=>judge(...args,...arg);方法被調用時才被執(zhí)行
這個curry后的函數(shù)只有在傳入的最后一個參數(shù)可以被轉換為false的時候才開始執(zhí)行,它存參數(shù)的方法也很簡單
1,判斷如果最后一個參數(shù)是否可以是false
2,是的話就把所有保存的參數(shù)放到fn里執(zhí)行,結束
3,否則,返回一個新的匿名函數(shù),這個函數(shù)把所有傳入?yún)?shù)保存在arg數(shù)組中,而這個匿名函數(shù)被執(zhí)行后,就把以前收到的參數(shù)數(shù)組和當前的參數(shù)數(shù)組合并后,放到前面說的邏輯中,在judge函數(shù)里判斷,重復第1步

let curry = function(fn) {
    var judge = function(...args) {
        if (Boolean(args[args.length - 1])===false) {
            return fn(args);//three(null)就到這里了
        } else {
            return function(...arg) { //one和two和three都是這個函數(shù)
                return judge(...args, ...arg);
            }
        }
    }
    return judge;
}
陌南塵 回答

在最前面全部聲明一下就行。

class class1;
class class2;

class class1
{
public:
    friend void Print(class1 &a, class2 &b);
};

class class2
{
public:
    friend void Print(class1 &a, class2 &b);
};
陌離殤 回答
如果當成執(zhí)行式的話,c++,++c,c+=1,c=c+1對程式設計師來說是相同的,
也就是說,在程式裡出現(xiàn):
c++;
++c;
c=c+1;
c+=1;
這四段程式碼執(zhí)行結果是相同的.

但如果拿來當表示式,就有所不同了,
c=7; x=c++; 執(zhí)行後c=8,x=7
c=7; x=++c; 執(zhí)行後c=8,x=8
c=7; x=c+=1; 執(zhí)行後c=8,x=8
也就是說++cc+=1會先執(zhí)行加的動作,
再拿其值來當表示式,
c++則是先拿其值來當表示式,再執(zhí)行加的動作.

http://www.programmer-club.co...

L33用的是k++,先把k=3賦給了m[3][0],之后再加。所以跟m[2][0]是一樣的。

建議:++k/k++永遠單獨放一行,不給自己找麻煩。事實上,因為這兩個語法太討厭,python這種以優(yōu)雅為設計原則的語言直接廢棄了這兩種語法。

茍活 回答

x += x+++x;
根據(jù)c語言的貪婪匹配原則,會被認為是x+=(x++)+x;x在+=時為11了,x+++x是10+11,最后應該是11+10+11,不過這是我自己猜的,這種在一個表達式中多次修改變量值的行為是ub,會因為編譯器不同可以有不同結果。

笨笨噠 回答

類型轉換

#include <iostream>

struct width{
    int w;
    constexpr operator int()const {
        return w;
    }
};
int main(void)
{
    width w{8};
    int i = w; // 隱式轉換
    int j = int(w); // 顯式
    int k = width(w);

    std::cout<<i<<j<<k;
}
---
888

附:參考鏈接

綰青絲 回答
  • 可以使用streambuf(二進制流)的方式直接動態(tài)分配內存

  • 同時使用read_until函數(shù)讀取結束符

  • 最后可以再轉換成string類型進行使用

boost::asio::streambuf pic_info;
boost::asio::read_until(socket, pic_info, "end", ec);
離殤 回答

很簡單的問題,npm這個報錯我也是服了,就是flash這個用戶名被注冊過了,換一個就好了,我解決了在這里記錄一下,怕以后忘了...

別逞強 回答

表達式"s"的類型是const char[],表達式 'a'的類型是char。

數(shù)組是不能進行內置加法運算的。所以const char []會被轉換成const char *,這里的運算就變成了"指針+整型"(char是一種整型)。輸出空行的運行結果實際上是數(shù)組越界引起的。

String literal
Narrow multibyte string literal. The type of an unprefixed string literal is const char[]

Additive operators
addition. For the built-in operator, lhs and rhs must be one of the following: Both have arithmetic or unscoped enumeration type. In this case, the usual arithmetic conversions are performed on both operands and determine the type of the result. One is a pointer to complete object type, the other has integral or unscoped enumeration type. In this case, the result type has the type of the pointer

Array-to-pointer decay
There is an implicit conversion from lvalues and rvalues of array type to rvalues of pointer type: it constructs a pointer to the first element of an array. This conversion is used whenever arrays appear in context where arrays are not expected, but pointers are.

浪婳 回答

首先, 你需要展示自己在解決這個問題的過程中做出了哪些嘗試, 搜了哪些東西, 得出些什么結論. 而不是這樣就扔個代碼.
先把這篇帖子讀了: https://stackoverflow.com/que...

為了充實下此答案, 稍微結合下你的問題說下, 雖然沒什么意義, 因為那篇帖子說的很好了, 不過沒有引用標準,
語言律師可能不是很喜歡, 所以我再補充些標準里的. (這是符合stackexchange的規(guī)則的, 因為我給出了原鏈):

雖然有了前置聲明, 但是編譯器并不知道Fsm的大小, 成員, 方法. 它此時被稱作incomplete type, 它是不能被解引用的(operator->其實也是解引用符), 所以你用vs的話雙擊error會調到幾行解引用的地方, compile time error了.

clipboard.png

夏木 回答
  1. 不會,
  2. 時間太小了,哪有你這么測試的。。
情殺 回答
public class Solution {
    /**
     * @param n an integer
     * @return a list of Map.Entry<sum, probability>
     */
    public List<Map.Entry<Integer, Double>> dicesSum(int n) {
        // Write your code here
        // Ps. new AbstractMap.SimpleEntry<Integer, Double>(sum, pro)
        // to create the pair
         List<Map.Entry<Integer, Double>> results = 
                new ArrayList<Map.Entry<Integer, Double>>();
        
        double[][] f = new double[n + 1][6 * n + 1];
        for (int i = 1; i <= 6; ++i)
            f[1][i] = 1.0 / 6;

        for (int i = 2; i <= n; ++i)
            for (int j = i; j <= 6 * n; ++j) {
                for (int k = 1; k <= 6; ++k)
                    if (j > k)
                        f[i][j] += f[i - 1][j - k];

                f[i][j] /= 6.0;
            }

        for (int i = n; i <= 6 * n; ++i) 
            results.add(new AbstractMap.SimpleEntry<Integer, Double>(i, f[n][i]));

        return results;
    }
}
離觴 回答
  1. 看你 5天前注冊的,是個新人,花時間跟你說說;
  2. 在這里大家都忙著問讓自己漲見識、學知識的問題;而回答的人也是這樣,幫助新人相互學習;
  3. 這類似機遇啥的問題,可以到 逼乎等地方問問;剛剛幫你搜了,沒有機遇這個標簽,創(chuàng)建標簽需要1.5K聲望,想想為什么要這么高的聲望才能創(chuàng)建標簽?
  4. 工作好不好找,去文章區(qū) 搜索面試題;如果大部分題目你都懂并能實現(xiàn),那很好找工作;
  5. 這個社區(qū)很溫暖,因為大家想建立的是一個知識性,權威,高質量的平臺;但是你這個問題如果很多別人幫你的話,以后可能出現(xiàn)更多類似的問題,我給踩你的人點贊。
  6. 本來也想抬手就一個踩,可能是現(xiàn)在心情很好,所以花時間跟你說這些,以后我也少逼逼,或者看到類似的問題直接踩;
  7. 總之,這種道理性的話題說不完,以后也更少人愿意說給你聽。

附上一張如何提問的圖:
圖片描述

陪妳哭 回答

一知半解,嘗試拋磚引玉:)

  1. &#x4E2D;&#x56FD; 并非 utf-8,而是HTML、XML 等 SGML 類語言的轉義序列(escape sequence)。它們不是「編碼」。以 HTML 為例,這三種轉義序列都稱作 character reference:第一種是 character entity reference,后接預先定義的 entity 名稱,而 entity 聲明了自身指代的字符。后兩種是 numeric character reference(NCR),數(shù)字取值為目標字符的 Unicode code point;以「&#」開頭的后接十進制數(shù)字,以「&#x」開頭的后接十六進制數(shù)字。NCR 以 Unicode 為準,與文檔編碼無關?!钢袊苟址謩e是 Unicode 字符 U+4E2D 和 U+56FD,十六進制表示的 code point 數(shù)值「4E2D」和「56FD」

所以。 其實上你可以理解是特定前綴+ Unicode ( 非 utf-8)編碼。 所以你看看其實和 unicode 是一樣的。

  1. % 是URL編碼規(guī)定的轉義前綴。 所以你看看這個其實和 utf-8 的中國是一樣一樣的(請刨除前綴看)
  2. 說實在的。。沒有看懂了。
陌顏 回答

您好,您這個問題解決了嗎,遇到類似的問題,方便給予解答嗎。 qq郵箱 137370999@qq.com 。謝謝!

蝶戀花 回答

可以的,之前我做項目的時候,只發(fā)布自己代碼打的jar就可以了,
其他jar單獨放上去,還有那些靜態(tài)資源一般都比較大,也傳一次不更新就不用再打包了

陌如玉 回答

槽點1:

BaseClass *b = new BaseClass();
std::shared_ptr<BaseClass> test(b->getInstance());

這是bad practice, 雖然還不是UB, 但是只有一步之遙了, 比如加一個std::shared_ptr<BaseClass> test2(b->getInstance());double delete了.

解決方法:

所以第一步要做的是把BaseClass *b = new BaseClass();修改成std::shared_ptr<BaseClass> b(new BaseClass);

到此結束了嗎? 不, 繼續(xù)噗:

槽點2:

  std::shared_ptr<BaseClass> getInstance()
  {
      return std::shared_ptr<BaseClass>(this);
  }
  

假設已經做出上述修改了, 由于上段代碼的存在, 依舊會杯具. 原因和上面類似, 因為test并不知道this已經被b用過了, 所以引用計數(shù)就gg了. 你需要自己實現(xiàn)一個shared_ptr就能理解了.

解決方法:

使用std::enable_shared_from_this:

class BaseClass :  enable_shared_from_this<S>
{
public:
  BaseClass(){cout << "BaseClass construct" << endl;}
  ~BaseClass(){cout << "Base destructor" << endl;}
  std::shared_ptr<BaseClass> getInstance()
  {
      return shared_from_this();
  }
};

想進一步了解可以去看enable_shared_from_this是如何實現(xiàn)的.

槽點3:

不存在disconstruct這種說法, 跟我念: destructor

槽點4:

永遠不要貼截圖(qq群里也一樣, 不通過markdown就用paste.ubuntu.

懶得打字這次我給你輸好了, 請貼近問題描述中:

#include <iostream>
#include <memory>
using namespace std;
class BaseClass;
class ChildClass;
typedef std::shared_ptr<BaseClass> BaseClassPtr;
typedef std::shared_ptr<ChildClass> ChildClassPtr;
class BaseClass
{
public:
  BaseClass(){cout << "BaseClass construct" << endl;}
  ~BaseClass(){cout << "Base destructor" << endl;}
  std::shared_ptr<BaseClass> getInstance()
  {
      return std::shared_ptr<BaseClass>(this);
  }
};
int main()
{
    BaseClass *b = new BaseClass();
    std::shared_ptr<BaseClass> test(b->getInstance());
    cout << "end" << endl;
}

槽點5:

你應該把這段代碼的鏈接發(fā)出來, 一方面展示自己從哪里獲取的信息, 一方面挺想看是誰寫出這樣的代碼的.

槽點6:

這是針對另一位答主的, 語言沒有規(guī)定是heap, 只說了是free store. 具體可以參見帝球此貼

槽點7:

這是一個c++的問題, 不要貼c的標簽, 完全兩門不搭界的語言.

焚音 回答

不需要的,proxyTable 只是在開發(fā)環(huán)境中起到代理的作用,解決開發(fā)環(huán)境的跨域問題;項目打包放到線上,需要后臺的配置下Nginx解決跨域問題。

首頁 上一頁 1 2 3 4 5 6 7 8 下一頁 尾頁