Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > .NET для новичков > std::vector


Автор: Metalex 21.1.2012, 14:57
При использовании вектора получаю кучу ошибок.

Код

#pragma once
#include "WResource.h"
#include <vector>

using namespace std;

class Catalog
{
    vector<WResource> catalog;
public:
    Catalog(void);
    void add(String ^ name, String ^ type, int volume, String ^ placement, int maxdepth, String ^ shortinfo);
    void show();
    void searchName(String ^ name);
    void searchType(String ^ type);
    void searchVolume(int volume);
    void searchPlacement(String ^ placement);
    void searchMaxdepth(int maxdepth);
};


Код

void Catalog::add(String ^ name, String ^ type, int volume, String ^ placement, int maxdepth, String ^ shortinfo) {
    WResource wr(name, type, volume, placement, maxdepth, shortinfo);
    catalog.push_back(wr);
}


Код

1>------ Build started: Project: WaterResources, Configuration: Debug Win32 ------
1>Compiling...
1>Catalog.cpp
1>D:\Program Files (x86)\Visual Studio 2005 (8)\VC\include\xmemory(96) : error C3699: '*' : cannot use this indirection on type 'WResource'
1>        compiler replacing '*' with '^' to continue parsing
1>        D:\Program Files (x86)\Visual Studio 2005 (8)\VC\include\vector(416) : see reference to class template instantiation 'std::allocator<_Ty>' being compiled
1>        with
1>        [
1>            _Ty=WResource
1>        ]
1>        D:\Program Files (x86)\Visual Studio 2005 (8)\VC\include\vector(426) : see reference to class template instantiation 'std::_Vector_val<_Ty,_Alloc>' being compiled
1>        with
1>        [
1>            _Ty=WResource,
1>            _Alloc=std::allocator<WResource>
1>        ]
1>        d:\all are here\!заказы\waterresources\waterresources\Catalog.h(9) : see reference to class template instantiation 'std::vector<_Ty>' being compiled
1>        with
1>        [
1>            _Ty=WResource
1>        ]
1>D:\Program Files (x86)\Visual Studio 2005 (8)\VC\include\xmemory(97) : error C3699: '&' : cannot use this indirection on type 'WResource'
1>        compiler replacing '&' with '^' to continue parsing
1>D:\Program Files (x86)\Visual Studio 2005 (8)\VC\include\xmemory(98) : error C3699: '*' : cannot use this indirection on type 'const WResource'
1>        compiler replacing '*' with '^' to continue parsing
1>D:\Program Files (x86)\Visual Studio 2005 (8)\VC\include\xmemory(99) : error C3699: '&' : cannot use this indirection on type 'const WResource'
1>        compiler replacing '&' with '^' to continue parsing
1>D:\Program Files (x86)\Visual Studio 2005 (8)\VC\include\xmemory(154) : error C3699: '&' : cannot use this indirection on type 'const WResource'
1>        compiler replacing '&' with '^' to continue parsing
1>D:\Program Files (x86)\Visual Studio 2005 (8)\VC\include\vector(473) : error C3699: '&' : cannot use this indirection on type 'const WResource'
1>        compiler replacing '&' with '^' to continue parsing
1>D:\Program Files (x86)\Visual Studio 2005 (8)\VC\include\vector(479) : error C3699: '&' : cannot use this indirection on type 'const WResource'
1>        compiler replacing '&' with '^' to continue parsing
1>D:\Program Files (x86)\Visual Studio 2005 (8)\VC\include\vector(531) : error C3699: '&' : cannot use this indirection on type 'const WResource'
1>        compiler replacing '&' with '^' to continue parsing
1>D:\Program Files (x86)\Visual Studio 2005 (8)\VC\include\vector(785) : error C3699: '&' : cannot use this indirection on type 'const WResource'
1>        compiler replacing '&' with '^' to continue parsing
1>D:\Program Files (x86)\Visual Studio 2005 (8)\VC\include\vector(846) : error C3699: '&' : cannot use this indirection on type 'const WResource'
1>        compiler replacing '&' with '^' to continue parsing
1>D:\Program Files (x86)\Visual Studio 2005 (8)\VC\include\vector(851) : error C3699: '&' : cannot use this indirection on type 'const WResource'
1>        compiler replacing '&' with '^' to continue parsing
1>D:\Program Files (x86)\Visual Studio 2005 (8)\VC\include\vector(858) : error C3699: '&' : cannot use this indirection on type 'const WResource'
1>        compiler replacing '&' with '^' to continue parsing
1>D:\Program Files (x86)\Visual Studio 2005 (8)\VC\include\vector(1058) : error C3699: '&' : cannot use this indirection on type 'const WResource'
1>        compiler replacing '&' with '^' to continue parsing
1>D:\Program Files (x86)\Visual Studio 2005 (8)\VC\include\vector(1116) : error C3699: '&' : cannot use this indirection on type 'const WResource'
1>        compiler replacing '&' with '^' to continue parsing
1>D:\Program Files (x86)\Visual Studio 2005 (8)\VC\include\vector(1206) : error C3699: '&' : cannot use this indirection on type 'const WResource'
1>        compiler replacing '&' with '^' to continue parsing
1>D:\Program Files (x86)\Visual Studio 2005 (8)\VC\include\vector(1243) : error C3265: cannot declare a managed '_Myfirst' in an unmanaged 'std::vector<_Ty>'
1>        with
1>        [
1>            _Ty=WResource
1>        ]
1>        may not declare a global or static variable, or a member of a native type that refers to objects in the gc heap
1>D:\Program Files (x86)\Visual Studio 2005 (8)\VC\include\vector(1244) : error C3265: cannot declare a managed '_Mylast' in an unmanaged 'std::vector<_Ty>'
1>        with
1>        [
1>            _Ty=WResource
1>        ]
1>        may not declare a global or static variable, or a member of a native type that refers to objects in the gc heap
1>D:\Program Files (x86)\Visual Studio 2005 (8)\VC\include\vector(1245) : error C3265: cannot declare a managed '_Myend' in an unmanaged 'std::vector<_Ty>'
1>        with
1>        [
1>            _Ty=WResource
1>        ]
1>        may not declare a global or static variable, or a member of a native type that refers to objects in the gc heap
1>Build log was saved at "file://d:\All are here\!Заказы\WaterResources\WaterResources\Debug\BuildLog.htm"
1>WaterResources - 18 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========



Помогите разобраться, пожалуйста.

Автор: Albor 21.1.2012, 15:45
На каком языке пишешь? Похоже на не совместимость с вектором, поскольку компилятор пытается поменять *  на ^ при использовании WResource.

Автор: mes 21.1.2012, 17:15
Metalex, для управляемых типов (.net) предназначен другой вектор : http://msdn.microsoft.com/en-us/library/bb386284.aspx
Цитата

Header: <cliext/vector>
Namespace: cliext

Автор: Metalex 21.1.2012, 19:23
Я пишу на с++. А почему обычный вектор не подходит?

Автор: mes 21.1.2012, 19:26
Цитата(Metalex @  21.1.2012,  18:23 Найти цитируемый пост)
Я пишу на с++. А почему обычный вектор не подходит? 

потому что приведенный выше код не на c++, а на c++/cli для .net

Автор: Metalex 21.1.2012, 19:53
Цитата(mes @  21.1.2012,  19:26 Найти цитируемый пост)
для .net

Т.е. создав обычное приложение windows forms я создал приложение для .net?

Автор: Dem_max 21.1.2012, 19:58
да

Автор: Metalex 22.1.2012, 03:10
Но это подходит только для 8й и 10й студии. Есть ли аналог для 5й?

Автор: Metalex 22.1.2012, 13:16
Или кто знает, подскажите, пожалуйста, как обойти данную несправедливость..

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)