简体   繁体   English

如何将CArray(MFC)移植到Linux

[英]how to port CArray (MFC) to linux

I am porting a windows app to linx. 我正在将Windows应用程序移植到linx。 I am trying to port CArray MFC Method to linux. 我正在尝试将CArray MFC方法移植到Linux。 The CArray to be ported is 要移植的CArray是

CArray<double,double> min;

I have made an equivalent of this like... 我做了类似的事情...

#include <iostream>
#include <vector>
#include <list>

int main ()
{
        struct values
        {
            double value1;
            double value2;
        };
        typedef std::vector<values> CArray;
        CArray min;
        CArray max;
    return 0;
}

but i am getting erros like... 但我越来越像...

vec1.cpp: In function ‘int main()’:
vec1.cpp:12:29: error: template argument for ‘template<class _Alloc> class std::allocator’ uses local type ‘main()::values’
vec1.cpp:12:29: error:   trying to instantiate ‘template<class _Alloc> class std::allocator’
vec1.cpp:12:29: error: template argument 2 is invalid
vec1.cpp:12:37: error: invalid type in declaration before ‘;’ token

Please if anybody has work on this porting of CArray to linux equivalent, please provide the solution. 如果有人在将CArray移植到Linux等价物上有任何工作,请提供解决方案。

You need to make your struct non-local type: 您需要使您的结构非本地类型:

#include <iostream>
#include <vector>
#include <list>

struct values
{
   double value1;
   double value2;
};

int main ()
{
        typedef std::vector<values> CArray;
        CArray min;
        CArray max;
    return 0;
}

However, instead of using struct to hold pair of values, you should benefit from C++ and use std::pair : 但是,应该使用Cd并使用std :: pair ,而不是使用struct来保存一对值:

#include <iostream>
#include <vector>
#include <list>
#include <utility>

typedef std::vector<std::pair<double, double> > CArray;

int main ()
{
    
    CArray min;
    CArray max;
    return 0;
}

The first line with error describes what the problem is: error的第一行描述了问题所在:

template argument for ‘template<class _Alloc> class std::allocator’ uses local type ‘main()::values’

Now, let's think... if the compiler complains about values being local to main, how can we fix that? 现在,让我们考虑一下...如果编译器抱怨values对于main来说是局部的,我们该如何解决呢? We could, perhaps make values not local to main? 我们可以使values不局限于主要values吗? So the answer you're looking for is to move the declaration of values outside of main and at global scope. 因此,您要寻找的答案是将values的声明移出main范围和全局范围。

Of course, the problem is that the question is wrong: it should be why you need a struct and two double values in your std::vector ? 当然,问题在于问题是错误的:这应该是为什么在std::vector需要一个struct和两个double值吗? After all, the CArray you showed us doesn't hold two double values. 毕竟,您展示给我们的CArray不包含两个double值。 It holds one so std::vector<double> should do the trick. 它拥有一个,因此std::vector<double>应该可以解决问题。 You may find the documentation for CArray helpful as you try to port this code. 尝试移植此代码时,您可能会发现CArray文档很有帮助。

MFC的CArray<double,double>的STL等效项是std::vector<double>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM