鍍金池/ 問答/ C++問答
乖乖噠 回答

先把代碼排版好

根據(jù)你的錯誤信息,你的編譯的命令行應(yīng)該有誤,順便一道貼出來看看

個人猜測,你是沒有加入Student.cpp的編譯:

cc main.cpp Student.cpp -o a.out
喵小咪 回答

問題已經(jīng)解決

結(jié)構(gòu)體中定義的是 string 類型,string 的長度可以是 3 或者6 任意長度,導(dǎo)致結(jié)構(gòu)體占用空間大小不確定。

脾氣硬 回答

這是Angular的:

$http({
    url: "",
    method: 'POST',
    timeout: 60000,
    headers: {'Content-Type': 'application/x-www-form-urlencoded;charset=utf8'},
    transformRequest: function(obj) {
        var str = [];
        for(var p in obj)
            str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
        return str.join("&");
    },
    data:{}
}).success(function (data) {
    var blob = new Blob([data], {type: "application/vnd.ms-excel;charset=utf-8"}),
        Temp = document.createElement("a");

    Temp.href = window.URL.createObjectURL(blob);
    Temp.download = "XXX.xlsx";
    angular.element('body').append(Temp);
    Temp.click();
});
舊顏 回答

%[0-9] 是一組字符的集合。比如 %[0-9] 表示會一直讀取 0 到 9 的字符,直到出現(xiàn)不是 0 到 9 的字符為止。

舉個例子 %c%c.%[0-9]E%d 對于:

+1.23400E-03

是這樣的:

  1. 使用 %c 讀入字符 +
  2. 使用 %c 讀入字符 1
  3. 使用 . 讀入字符 .
  4. 使用 %[0-9] 讀入字符 23400
  5. 使用 E 讀入字符 E
  6. 使用 %d 讀入字符 03
朽鹿 回答

我覺得可以這樣理解

首先理解方法本身的意思:
Streamreduce方法,翻譯過來是聚合或者是匯聚成一個的意思,由于Stream本身就代表著一堆數(shù)據(jù),那stream.reduce()方法顧名思義就是把一堆數(shù)據(jù)聚合成一個數(shù)據(jù)

理解了reduce方法的意思,再來看看這個方法掛靠的對象是stream,是一個流,了解一下流的工作方式:
流底層核心其實是Spliterator接口的一個實現(xiàn),而這個Spliterator接口其實本身就是Fork/Join并行框架的一個實現(xiàn),所以歸根結(jié)底要明白流的工作方式,就要明白一下Fork/Join框架的基本思想,即:以遞歸的方式將可以并行的任務(wù)拆分成更小的子任務(wù),然后將每個子任務(wù)的結(jié)果合并起來生成整體的最后結(jié)果,畫了個草圖如下

clipboard.png

理解了方法本身的意思以及流的工作方式,再結(jié)合到一起理解一下stream.reduce()方法,即用Fork/Join的方式把一堆數(shù)據(jù)聚合成一個數(shù)據(jù),因此可以畫出reduce方法的運(yùn)行草圖

clipboard.png

結(jié)合草圖,要實現(xiàn)stream.reduce()方法,必須要告訴JDK

  1. 你有什么需求數(shù)據(jù)要匯聚?(Stream已經(jīng)提供了數(shù)據(jù)源,對應(yīng)上面草圖的A元素)

  2. 最后要匯聚成怎樣的一個數(shù)據(jù)類型(對應(yīng)reduce方法的參數(shù)一,對應(yīng)上面草圖的B元素)

  3. 如何將需求數(shù)據(jù)處理或轉(zhuǎn)化成一個匯聚數(shù)據(jù)(對應(yīng)reduce方法的參數(shù)二,對應(yīng)上面草圖的匯聚方式1)

  4. 如何將多個匯聚數(shù)據(jù)進(jìn)行合并(對應(yīng)reduce方法的參數(shù)三,對應(yīng)上面草圖的匯聚方式2)

再結(jié)合你給的map方法,其實是要把O類數(shù)據(jù)的流,最后轉(zhuǎn)化為一個I類數(shù)據(jù)的List,因此按照上面的步驟可以進(jìn)行對照

  1. 你有什么需求數(shù)據(jù)要匯聚?(O類數(shù)據(jù)流)

  2. 最后要匯聚成怎樣的一個數(shù)據(jù)類型(一個集合,new ArrayList()

  3. 如何將需求數(shù)據(jù)處理或轉(zhuǎn)化成一個匯聚數(shù)據(jù)(根據(jù)mapper把O轉(zhuǎn)化為I,再用List.add方法)

  4. 如何將多個匯聚數(shù)據(jù)進(jìn)行合并(兩個集合合并,用List.addAll()

最后補(bǔ)充一點,若是你的參數(shù)真是Stream<I> streamFunction<I, O> mapper,建議不要用reduce方法,這么寫可能會更好一點

public static <I, O> List<O> map(Stream<I> stream, Function<I, O> mapper) {
        return stream.map(mapper).collect(Collectors.toList());
    }
傻丟丟 回答

lstrip用法如下:str. lstrip([chars])
lstrip會刪除你后面出現(xiàn)的所有可能的字符串,知道字符串不存在那個列表里。

比方說,str.lstrip('say')
str依次被去除首尾在['s','a','y']數(shù)組內(nèi)的字符,直到字符在不數(shù)組內(nèi)

下面是具體的樣例:

>>> '   spacious   '.lstrip()
'spacious   '
>>> "AABAA".lstrip("A")
'BAA'
>>> "ABBA".lstrip("AB") # both AB and BA are stripped
''
>>> "ABCABBA".rstrip("AB")
'ABC'
>>> "ABCABBA".lstrip("AB")
'CABBA'
網(wǎng)妓 回答

編譯時加上 -DCMAKE_PREFIX_PATH=path/to/qt5widgets 試一試

夏木 回答

VMT is implementation dependent, so topics should be limited to compilers implementations rather than c++ itself.

那么虛表是在什么時候生成的呢. 是在構(gòu)造函數(shù)執(zhí)行之前還是在構(gòu)造函數(shù)之后之后呢?

For Most compilers, virtual table pointer initializes __vptr at constructor's initializer list.


而且虛表存放在哪里呢?

What confuses you is where __vptr is(not VMT, because VMT just consists of the addresses of trivial non-virtual functions which can be invoked by __vptr), then:

Compilers have multiple choices(all as a hidden member), you can refer to here

Summary: Where is the __vptr stored in an object (first or last are the usual answers).

Of course, you can implement VMT with c, then you will not ask such questions.

BTW, this is not good (even is a bad) question, because you even haven't searched it on google before asking, so -1.

Update:

Wikipedia is also your friend.

已經(jīng)解決了問題,首先要修改一下pom.xml中的build里面的配置。
然后要把本地的jar包都用maven來進(jìn)行管理。
貼上我的pom.xml文件供大家參考。

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.qd</groupId>
    <artifactId>portal</artifactId>
    <version>1.0.0</version>
    <packaging>war</packaging>

    <name>portal</name>
    <description>Intelligence Connect Electric Drill</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.8.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <!--<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            &lt;!&ndash;<scope>provided</scope>&ndash;&gt;
        </dependency>-->
        <!--<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>-->
        <!-- 添加mysql的依賴 -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <!-- 添加jpa的支持 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>4.3.12.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>com.qd</groupId>
            <artifactId>commons</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>net.minidev</groupId>
            <artifactId>json-smart</artifactId>
            <version>2.2.1</version>
        </dependency>

        <dependency>
            <groupId>com.aliyun.oss</groupId>
            <artifactId>aliyun-sdk-oss</artifactId>
            <version>2.8.2</version>
        </dependency>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.8.2</version>
        </dependency>

        <!-- 嘗試加一下core依賴 -->
        <dependency>
            <groupId>com.qd</groupId>
            <artifactId>core</artifactId>
            <version>1.0.0</version>
        </dependency>

        <!-- 把他們都改成maven引入,1-16 -->
        <dependency>
            <groupId>com.aliyun</groupId>
            <artifactId>aliyun-java-sdk-core</artifactId>
            <version>3.2.3</version>
        </dependency>

        <dependency>
            <groupId>com.aliyun</groupId>
            <artifactId>aliyun-java-sdk-dysmsapi</artifactId>
            <version>1.0.0</version>
        </dependency>

        <dependency>
            <groupId>net.sf.json-lib</groupId>
            <artifactId>json-lib</artifactId>
            <version>2.4</version>
            <classifier>jdk15</classifier>
        </dependency>

        <!-- Mqtt -->
        <dependency>
            <groupId>org.eclipse.paho</groupId>
            <artifactId>org.eclipse.paho.client.mqttv3</artifactId>
            <version>1.1.0</version>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>


</project>
涼薄 回答

內(nèi)存這個應(yīng)該不用觀察吧.
每個進(jìn)程的內(nèi)存空間都是獨(dú)立的, 進(jìn)程掛了, 操作系統(tǒng)給她分配的內(nèi)存都會回收掉.

至于其他需要釋放的資源怎么處理, 這里要看你說的資源都是啥.
內(nèi)存/文件/鎖/數(shù)據(jù)庫鏈接/共享消息等.
如果是進(jìn)程內(nèi)資源, 那操作系統(tǒng)負(fù)責(zé)回收, 如果是跨進(jìn)程的資源,比如和另外個進(jìn)程共用一把鎖, 這個時候進(jìn)程A掛了,進(jìn)程B就拿不到鎖了, 如果進(jìn)程B也沒有鎖的超時機(jī)制,那就有問題了.

更進(jìn)一步, 如果你把"資源"限定在為一個一組對稱的操作的話, 也不會釋放. 比如進(jìn)程啟動初始化了一堆文件, destroy的時候應(yīng)該全部刪除. 這個活兒操作系統(tǒng)不會幫你干,進(jìn)程掛了的時候也沒有釋放.

妖妖 回答

我有用過這個,你不要用他那個數(shù)據(jù)來平均等分,而是用另一種方法,比如你的有9份,有3種顏色,那就是分成3份,我目前知道的就這樣解決,我也沒有找到整數(shù)的api。總之你要用另一種方法給他搞成整數(shù)。

痞性 回答

有沒有嘗試用Bus呢?
用法如下

//假設(shè) bb 組件里面有個按鈕,點擊按鈕,把 123 傳遞給 aa 組件
// 根組件(this.$root)
new Vue({
 el: '#app',
 router,
 render: h => h(App),
 data: {
  // 空的實例放到根組件下,所有的子組件都能調(diào)用
  Bus: new Vue()
 }
})

bb 組件內(nèi)調(diào)用事件觸發(fā)↓
<button @click="submit">提交<button>

methods: {
  submit() {
   // 事件名字自定義,用不同的名字區(qū)別事件
   this.$root.Bus.$emit('eventName', 123)
  }
 }


aa 組件內(nèi)調(diào)用事件接收↓
 // 當(dāng)前實例創(chuàng)建完成就監(jiān)聽這個事件
 created(){
  this.$root.Bus.$on('eventName', value => {
   this.print(value)
  })
 },

 methods: {
  print(value) {
   console.log(value)
  }
 },

 // 在組件銷毀時別忘了解除事件綁定
 beforeDestroy() {
   this.$root.Bus.$off('eventName')
 },
別傷我 回答

完全同意@lcp0578的看法。
算法和數(shù)據(jù)結(jié)構(gòu)和語言無關(guān)。

久舊酒 回答

void fun(int *q,int *p,int *w);修改的是指針指向的內(nèi)容(a, b, c)。void fun_(int *q,int *p,int *w);修改的是指針本身,而不是指向的內(nèi)容。

淚染裳 回答

你加個插件配置plugins,讓構(gòu)建好的js自動給引入到頁面去圖片描述

假灑脫 回答
  1. C++的代碼為什么要放java的標(biāo)簽?
  2. 問題排版成這樣難道不知道編輯嗎?

言歸正傳
編譯報錯是最好debug的錯誤之一,所有的錯誤編譯器都明確告訴你了

請看代碼中的這一行:

vmm[i].insert(it->first,count);

這里vmm[i] 是一個 map<int,char*>, 且不說插入值的時候需要用pair<int, char*>包裝鍵值對,it->first是一個intcount也是一個int,值的類型和map的定義不符。

如果不在乎insert的返回值的話,個人覺得用map[key] = value的方式更簡潔

淺時光 回答

grid[i] 是個int* 不錯,但是你的grid[i]指向哪里了你?你沒有為它分配內(nèi)存。

函數(shù)傳入的grid有什么意義呢?

爆扎 回答

既然你了解了引用折疊, 我相信你也應(yīng)該知道了forward就是一簡單的static_cast<T&&>t.

此函數(shù)void process(T&& t)是有問題的, 它依舊是一個universal reference/forwarding reference , 只有void process(int&& t)這樣明確是右值引用你才能稱作rv, 對吧. 所以先改下函數(shù)并簡化代碼:

template <typename T> void process(const T& t) { cout << "const T&" << endl; }
template <typename T> void process(T&& t)      { cout << "T&&" << endl; }
void test(...) { process(...) ;}

因為forward只是一個轉(zhuǎn)發(fā)(從上面的實現(xiàn)配合引用折疊也是很好理解的), 并且能保留原有的ref-qualifier和const-qualifier, 所以被稱作完美轉(zhuǎn)發(fā), 因此你可以把test里面的process繼續(xù)簡化掉:

int non_const_a = 1;
int const const_a = 1; 
template <typename T> void process(const T& t) { cout << "const T&" << endl; }
template <typename T> void process(T&& t)      { cout << "T&&" << endl; }
test(1); // T&&
test(non_const_a); // T&&
test(const_a); // const T&

有沒有發(fā)現(xiàn)什么? 整個過程其實就是簡化成左值, 右值, 加上const-qualifier對process的函數(shù)重載決議了.

無論T&&還是const T&都和標(biāo)題中的forward, 右值引用沒什么關(guān)系了

這下應(yīng)該明白了吧? 只有const的左值才會匹配const T&, 其他都會匹配T&&. 很明了的一個重載決議.


繼續(xù), 可能OP會想, 如果我這么重載呢?

template <typename T> void process(const T& t) { cout << "const T&" << endl; }
template <typename T> void process(const T&& t)      { cout << "T&&" << endl; }

都有const呀, 此時該怎么辦呢? 編譯器是不是就gg了?

clipboard.png

簡單的說, 此時const T&&不再是人見人愛花見花開的, forwarding reference, 因為有了const-qualifier, 所以退化成了rvalue-reference了. g(i)妄想傳個左值進(jìn)去不是作么. 比如這樣的例子:

void f(int&& a) {} 
int main()
{
    int a = 1;
    f(a);
}

prog.cc:5:12: error: cannot bind rvalue reference of type 'int&&' to lvalue of type 'int'

 f(a);

有了以上鋪墊, OP是不是能想出之前提的問題:

#include <utility>
#include <iostream>

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

template
<typename T>
void process(const T& t)
{
    cout << "const T&" << endl;
}

template
<typename T>
void process(const T&& t)
{
    cout << "const T&&" << endl;
}

template
<typename T>
void test(T&& t)
{
    process(std::forward<T>(t));
}

int main()
{
    int a = 1;
    const int const_a = 1;
    test(1);
    test(a);
    test(const_a);
}
const T&&
const T&
const T&

可見只有右值1匹配了const T&&, 畢竟人家只能匹配右值嘛, 也是應(yīng)該的.