473,395 Members | 1,554 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

error "cannot use this type here without a top-level '^'" ??

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

Feb 7 '06 #1
10 23012
Hello Ramesh,
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;
};


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"
Feb 7 '06 #2
<as*******@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
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^>^ and not array<String>^
Feb 7 '06 #3
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...
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

Feb 7 '06 #4
Thanks to everyone for timely reply.

Regards,
Ramesh

Feb 7 '06 #5
"Peter Oliphant" <po*******@RoundTripInc.com> wrote in message
news:Og**************@TK2MSFTNGP15.phx.gbl...
... 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.


That's not true. You can have methods on value types, but you must have a
no-args constructor.

-cd
Feb 7 '06 #6
Didn't know that. Thanx! You say you can have other methods (other than a
constructor) on value types. Can they have arguments?

Also, how would you find this info on MSDN2? Looking up the word 'value', as
you can imagine, returns so many responses it's nearly intractable to find
the one based on what we mean here by 'value'...

[==P==]

"Carl Daniel [VC++ MVP]" <cp*****************************@mvps.org.nospam >
wrote in message news:%2****************@TK2MSFTNGP10.phx.gbl...
"Peter Oliphant" <po*******@RoundTripInc.com> wrote in message
news:Og**************@TK2MSFTNGP15.phx.gbl...
... 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.


That's not true. You can have methods on value types, but you must have a
no-args constructor.

-cd

Feb 8 '06 #7
Peter Oliphant wrote:
typedef array<ValueStruct^> Legal_Value_Ptr_Array ;


ValueStruct^ is not a pointer to a value, but a value boxed into an
anonymous ref class. The caret symbol always implies a garbage collected
ref class. You can't get a pointer to a value, but you can get a
reference to it: ValueStruct%.

Be careful with that, because

ValueStruct^ ptr = value;

will not create a pointer to the value, but instead it will create a
distinct boxed *copy* of it. If you start modifying "ptr", it won't have
any affect to the original value, because they're separate, unrelated
instances.

Tom
Feb 8 '06 #8
Thanks, Tom!

Sorry for my bad info. I still can't get use to this implicit boxing
thang... : )

[==P==]

"Tamas Demjen" <td*****@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Peter Oliphant wrote:
typedef array<ValueStruct^> Legal_Value_Ptr_Array ;


ValueStruct^ is not a pointer to a value, but a value boxed into an
anonymous ref class. The caret symbol always implies a garbage collected
ref class. You can't get a pointer to a value, but you can get a reference
to it: ValueStruct%.

Be careful with that, because

ValueStruct^ ptr = value;

will not create a pointer to the value, but instead it will create a
distinct boxed *copy* of it. If you start modifying "ptr", it won't have
any affect to the original value, because they're separate, unrelated
instances.

Tom

Feb 8 '06 #9
Peter Oliphant wrote:
Didn't know that. Thanx! You say you can have other methods (other
than a constructor) on value types. Can they have arguments? Yes, there are no restrictions on value types methods.
Also, how would you find this info on MSDN2? Looking up the word
'value', as you can imagine, returns so many responses it's nearly
intractable to find the one based on what we mean here by 'value'...


When looking for this kind of information (pure language rules), I found the
ECMA specification more usefull that MSDN (I found the MSDN2 organization
concerning C++/CLI language very poor). See
http://www.ecma-international.org/pu...T/ECMA-372.pdf.
What you're looking for is explained in excrutiating details in §22.2.
This reference may not be easy to read when you're not used to it, but
you're sure to find anything language-related in it, in a rather logical
organization IMHO.

Arnaud
MVP - VC
Feb 9 '06 #10
Wow! Nice reference (the link)! Thanx! : )

[==P==]

"Arnaud Debaene" <ad******@club-internet.fr> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Peter Oliphant wrote:
Didn't know that. Thanx! You say you can have other methods (other
than a constructor) on value types. Can they have arguments?

Yes, there are no restrictions on value types methods.
Also, how would you find this info on MSDN2? Looking up the word
'value', as you can imagine, returns so many responses it's nearly
intractable to find the one based on what we mean here by 'value'...


When looking for this kind of information (pure language rules), I found
the ECMA specification more usefull that MSDN (I found the MSDN2
organization concerning C++/CLI language very poor). See
http://www.ecma-international.org/pu...T/ECMA-372.pdf.
What you're looking for is explained in excrutiating details in §22.2.
This reference may not be easy to read when you're not used to it, but
you're sure to find anything language-related in it, in a rather logical
organization IMHO.

Arnaud
MVP - VC

Feb 9 '06 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Kragen Sitaker | last post by:
ERROR: Cannot insert a duplicate key into unique index pg_class_relname_nsp_index We've been getting this error in our application every once in a while --- typically once an hour to once a day,...
6
by: juli | last post by:
I declared: public delegate void PaintEventHandler(object objSender,PaintEventArgs pea); and this.Paint+=new PaintEventHandler(MyPaintHandler); and the: static void MyPaintHandler(object...
0
by: weixian_shen | last post by:
I'm trying to call my DLL written in C, and got the error: Cannot marshal field 'b' of type 'mystruct': There is no marshaling support for this type. The 2 functions in the DLL are: void...
1
by: Vycka | last post by:
Hello, There is a enterprise web application that is based on asp.net technologies and works on Microsoft IIS. The total number of users is 850. When the load of system gets very high, the...
2
by: moondaddy | last post by:
I have a simple sample site I'm building in asp.net 2.0. I created a master page and a default.aspx content page in the project's root directory. Then I created a subfolder called content and...
4
usafshah
by: usafshah | last post by:
Hi all, I installed a script and as i run it gives the following error: Fatal error: Cannot use object of type Session as array in c:\www\musicbox\index.php on line 2692 index.php ---> line...
2
by: Elliott | last post by:
Hello Everyone, I have a function in a header (KeyDialog.h) as such: void setKey(Key&); The function implementation is as such (KeyDialog.cpp): void KeyDialog::setKey(Key& k1) {
1
by: mudasserrafiq | last post by:
I am using following asp file default.asp <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <META http-equiv=Content-Type content="text/html; charset=windows-1252"> <META content="0...
1
by: srilathaapi | last post by:
Hi All, I am getting the error cannot redeclare the class some xxx in file xxx.php. bcz i m including xxx.php in 3 diffrent functions in the same file to invoke the 3 differnet functions in the...
5
by: Just Another Victim of the Ambient Morality | last post by:
I have a peculiar bug in my PHP code. It looks something like this: Fatal error: Cannot redeclare func_name() (previously declared in script.php:57) in script.php on line 57 I've done a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.