错误“不能在没有顶级'^'的情况下使用此类型?? [英] error "cannot use this type here without a top-level '^'" ??

查看:126
本文介绍了错误“不能在没有顶级'^'的情况下使用此类型??的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到以下编译错误

C3149:''System :: String'':如果没有顶级的话,这里不能使用这种类型

''^'' 。


有人可以解释我为什么会收到此错误吗?


这里是代码...

ImageFileData .h

---------------------------


公开value class ImageFileData

{

public:

ImageFileData();

~ImageFileData();


array< String> ^ getKeywords(); /// ERRRROR

private:

array< String> ^ m_sKeyword;

};

ImageFileData.cpp

------------------------ ----

数组< String> ^ ImageFileData :: getKeywords()

{

返回m_sKeyword;

}

谢谢

Ramesh

I get following compilation error
C3149: ''System::String'' : cannot use this type here without a top-level
''^''.

Could someone explain why I get this error?

here is the code...
ImageFileData.h
---------------------------

public value class ImageFileData
{
public:
ImageFileData();
~ImageFileData();

array<String>^ getKeywords() ;///ERRRROR
private:
array<String>^ m_sKeyword;
};
ImageFileData.cpp
----------------------------
array<String>^ ImageFileData :: getKeywords( )
{
return m_sKeyword;
}
Thanks
Ramesh

推荐答案

Hello Ramesh,
Hello Ramesh,
我得到以下编译错误
C3149:''S ystem :: String'':如果没有顶层,则不能使用此类型
''^''。
...
数组< String> ^ getKeywords(); /// ERRRROR
私有:
数组< String> ^ m_sKeyword;
};
I get following compilation error
C3149: ''System::String'' : cannot use this type here without a top-level
''^''.
...
array<String>^ getKeywords() ;///ERRRROR
private:
array<String>^ m_sKeyword;
};




声明m_sKeyword的第二行也会得到错误。

效果更好:

数组< String ^> ^ getKeywords();

私有:

array< String ^> ^ m_sKeyword;


从MSDN关于数组关键字:有效类型是托管引用类型

(类型^),托管值类型(类型)和本机指针(类型*)。


这意味着如果你想把字符串放在那里,你必须使用字符串

参考。

-


亲切的问候,

布鲁诺。
BR ********************** @ hotmail.com

仅删除_nos_pam



the second line that declares m_sKeyword will also get that error.
This works better:
array<String ^>^ getKeywords();
private:
array<String ^>^ m_sKeyword;

From MSDN about the array keyword: Valid types are managed reference types
(type^), managed value types (type), and native pointers (type*).

This means that if you want to put strings in there, you have to use string
references.
--

Kind regards,
Bruno.
br**********************@hotmail.com
Remove only "_nos_pam"


< as * ******@gmail.com>在消息中写道

news:11 ********************** @ g43g2000cwa.googlegr oups.com ...
<as*******@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
我得到以下编译错误
C3149:''System :: String'':如果没有顶级的话,就不能使用这种类型
''^''。
I get following compilation error
C3149: ''System::String'' : cannot use this type here without a top-level
''^''.

Could someone explain why I get this error?




array< String ^> ^而不是数组< String> ^



array<String^>^ and not array<String>^


根据我的经验,这些是规则。如果你创建一个''ref''类/结构,

数组'可能只包含指向元素的指针而不是实例

本身。如果你想要存储在数组中的实际实例,你必须

创建''value''结构。这些有利于你不能拥有任何

方法,不包括任何构造函数。


ref class RefClass {}; < br $>
value struct ValueStruct {};


typedef array< RefClass> NOT_Legal_Ref_Inst_Array;

typedef array< RefClass ^> Legal_Ref_Ptr_Array;


typedef array< ValueStruct> Legal_Value_Inst_Array;

typedef array< ValueStruct ^> Legal_Value_Ptr_Array;


[== P ==]


< as ******* @ gmail.com>在消息中写道

news:11 ********************** @ g43g2000cwa.googlegr oups.com ...
In my experience, these are the rules. If you create a ''ref'' class/struct,
array''s may only consist of pointers to elements and not the instances
themselves. If you want the actually instances stored in the array, you must
create ''value'' struct. These have the dis-advantage that you can''t have any
methods, incuding no constructors, for them.

ref class RefClass {} ;
value struct ValueStruct{ } ;

typedef array<RefClass> NOT_Legal_Ref_Inst_Array ;
typedef array<RefClass^> Legal_Ref_Ptr_Array ;

typedef array<ValueStruct> Legal_Value_Inst_Array ;
typedef array<ValueStruct^> Legal_Value_Ptr_Array ;

[==P==]

<as*******@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
我得到以下编译错误
C3149:''System :: String'':如果没有顶级的话,就不能使用这种类型
''^''。

这里是代码......
ImageFileData.h
------------- --------------

公共价值类ImageFileData
{
公开:
ImageFileData();
〜 ImageFileData();

数组< String> ^ getKeywords(); /// ERRRROR
private:
array< String> ^ m_sKeyword;
};

ImageFileData.cpp
----------------------------
array< String> ^ ImageFileData :: getKeywords()
{
返回m_sKeyword;
}

谢谢
Ramesh
I get following compilation error
C3149: ''System::String'' : cannot use this type here without a top-level
''^''.

Could someone explain why I get this error?

here is the code...
ImageFileData.h
---------------------------

public value class ImageFileData
{
public:
ImageFileData();
~ImageFileData();

array<String>^ getKeywords() ;///ERRRROR
private:
array<String>^ m_sKeyword;
};
ImageFileData.cpp
----------------------------
array<String>^ ImageFileData :: getKeywords( )
{
return m_sKeyword;
}
Thanks
Ramesh



这篇关于错误“不能在没有顶级'^'的情况下使用此类型??的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆