在我的程序中,我基本上有一个类似于的方法:
for (int x=0; x<numberofimagesinmyfolder; x++){
for(int y=0; y<numberofimagesinmyfolder; y++){
compare(imagex,imagey);
if(match==true){
System.out.println("image x matches image y");
}
}
}
Run Code Online (Sandbox Code Playgroud)
所以基本上我有一个图像文件夹,我比较所有图像组合...所以比较图像1与所有图像,然后图像2 ......等等.我的问题是在搜索什么图像匹配时,需要很长时间.我试图多线程这个过程.有没有人知道如何做到这一点?
我正在尝试为另一个类创建一个朋友函数,但我当前的布局导致访问问题和header-include问题.
在我的项目中,我有两个文件:A类和B类.为了简洁起见,所有内容都在头文件中内联,因为它仍然表明了我的问题.
#ifndef CLASSA
#define CLASSA
#include "ClassB.h"
class A {
private:
int x;
public:
A(int x) {
this->x = x;
}
friend void testFriend(A in);
};
#endif
#pragma once
#ifndef CLASSB
#define CLASSB
#include <cstdio>
#include "ClassA.h"
class B {
public:
void testFriend(A in) {
printf("%d", in.x);
}
};
#endif
Run Code Online (Sandbox Code Playgroud)
但是,使用此设置,Visual Studio认为类A的私有成员元素是不可访问的,尽管它是成员函数.此外,它们相互包含,最终会导致错误.但是,当这两个类位于同一个头文件中时,此设置可以正常工作.我怎样才能实现这样的设置,其中一个类具有需要与另一个类成为朋友的成员函数,并且将这两个类放在单独的头文件中.
我知道静态可以为c ++中的东西提供持久性,但我很困惑什么时候有必要.
例如,如果我有一个功能:
const int get5(){
int x = 5;
return x;
}
Run Code Online (Sandbox Code Playgroud)
而且我打印出来的回报,5会自然出现.但是,如果我对数组尝试相同:
const int* getArray() {
int arr[5];
arr[0] = 5;
arr[1] = 6;
arr[2] = 7;
arr[3] = 8;
arr[4] = 9;
return arr;
}
Run Code Online (Sandbox Code Playgroud)
我迭代遍历数组的每个元素,我只是变得格格不入:
const int* ptr = getArray();
for (int index = 0; index < 5; index++) {
cout << ptr[index] << endl;
}
Run Code Online (Sandbox Code Playgroud)
结果:
5
19920968
257848734
258124688
258124688
Run Code Online (Sandbox Code Playgroud)
但是,如果我使用static修饰符为arr添加前缀,并赋予其持久性,则它可以:
5
6
7
8
9
Run Code Online (Sandbox Code Playgroud)
我的问题是,为什么我需要将数组声明为静态,因为它的值是持久的,但在其他类型中,它没有必要?谢谢!
在我的程序中,我从一个不同长度的文本文件中读取了一行...它是完整的1和0,我如何取这个字符串并将其划分为一个int数组?基本上如果我有"011101"我想把它变成一个int数组,所以元素0的值为零,元素一的值为1,依此类推......