小编Pas*_*stx的帖子

未知的返回类型错误(C++)

我的问题是我需要首先定义我的接口,然后在代码中进一步实现它,但我的问题是,当我实现方法时,应该返回类内部已知类型的函数似乎在类外部未知.

这是我的代码:

class Test {
    class Inner {
    };    
public:    
    Inner* foo (void);
};

Inner* Test::foo(){
}
Run Code Online (Sandbox Code Playgroud)

此代码产生错误,因为类型Inner对于类外部的函数是未知的.任何人都可以帮助我如何创建只返回类内部定义的类型的简单函数?

感谢您的任何帮助.

c++

5
推荐指数
3
解决办法
202
查看次数

二维动态数组(c中的realloc)

我试图从输入加载两个双数字动态地由每个用户输入重新定位的二维数组.

#include <stdio.h>
#include <stdlib.h>


int main(int argc, char** argv) {

    int count;
    double number1, number2, **numbers;

    while (scanf("%lf,%lf", number1, number2) != EOF) {

        count++;
        numbers = (double**) realloc(numbers, count * 2 * sizeof (double));
        if (numbers == NULL) {
            exit(1);
        }
        numbers[count][0] = number1;
        numbers[count][1] = number2;
    }

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

每次我尝试将值保存到数组(可能是内存问题)时程序失败.它编译没有问题.

任何人都可以告诉我如何正确地重新分配新阵列?

谢谢你的帮助.

c arrays realloc

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

按位c ++读取文件

我有二进制文件作为输入,我需要逐位读取它.如果我想按字符读取文件,我会使用这个:

    ifstream f(inFile, ios::binary | ios::in);
    char c;
    while (f.get(c)) {
        cout << c;
    }
Run Code Online (Sandbox Code Playgroud)

这段代码的输出是字符序列,我需要的是1和0的序列.函数get()返回下一个字符,我找不到任何返回下一位的ifstream函数.

有没有类似的方法如何实现呢?

感谢任何人的帮助.

c++ ifstream

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

传递对象C++的常量引用

这是我的代码:

#include <cstdlib>
#include <vector>
#include <iostream> 
#include <cstring>  

using namespace std;

class GeneralMatrix {
public:
    GeneralMatrix(const string & n, int nr, int nc);
    GeneralMatrix * add (const GeneralMatrix&);
    const double get(int row, int col){}
    void set(int row, int col, double val){}
};

GeneralMatrix * GeneralMatrix::add(const GeneralMatrix& m2){
if (height != m2.height || width != m2.width) {
            throw "Matrix sizes must match!";
        }
        for (int i = 0; i < height; i++) {
            for (int j = 0; j < …
Run Code Online (Sandbox Code Playgroud)

c++

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

Thymeleaf 在 Docker 容器内运行时无法解析模板

我有一个 SpringBoot 应用程序的标准项目结构: src/main/java 用于 src 文件和 src/main/resources

当我像这样构建并运行我的应用程序时:

mvn clean install
mvn spring-boot:run
Run Code Online (Sandbox Code Playgroud)

一切正常。

当我尝试在 docker-compose 指定的 docker 容器内运行时

file:
version: "3.1"
services:
  app:
    container_name: thdnes-app
    restart: always
    build:
      context: ./
      dockerfile: Dockerfile
    ports:
      - "8080:8080"
Run Code Online (Sandbox Code Playgroud)

和 Dockerfile:

FROM openjdk:11-jdk
VOLUME /tmp
COPY /target/thdnes-0.0.1-SNAPSHOT.jar app.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","app.jar"]
Run Code Online (Sandbox Code Playgroud)

SpringBoot 启动正常(通过控制台输出判断,没有错误)。

但是当我导航到http://localhost:8080/login 时出现错误:

thdnes-app | 2019-07-26 13:32:11.361 ERROR 1 --- [nio-8080-exec-1] org.thymeleaf.TemplateEngine             : [THYMELEAF][http-nio-8080-exec-1] Exception processing template "/login.html": Error resolving template [/login.html], template might not exist or might not be accessible by any of …
Run Code Online (Sandbox Code Playgroud)

thymeleaf docker spring-boot docker-compose

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

在向量C ++的索引处插入对象

我需要将一个对象插入到对象的现有向量中。我知道我需要使用迭代器来做到这一点,但我不知道它是如何工作的。

我按字母顺序对向量进行排序,我需要按搜索后得到的确切索引,按其名称插入新对象。所以我有这个。

vector<Person>people;


int index =54;
Person temp;

people.push_back(temp);//insert at end of vector
people.insert(index, temp);//doesnt work for int
Run Code Online (Sandbox Code Playgroud)

谁能帮助我如何正确使用迭代器将我的对象插入向量的54索引并将所有后续对象移动一个索引?

感谢您的任何帮助。

c++ vector

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

标签 统计

c++ ×4

arrays ×1

c ×1

docker ×1

docker-compose ×1

ifstream ×1

realloc ×1

spring-boot ×1

thymeleaf ×1

vector ×1