Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

how to sub-class an AnsiString

Posted on 2014-02-05
5
Medium Priority
?
591 Views
Last Modified: 2014-02-05
I wish to derive a class from an AnsiString in BCB5 or Embarcadero EX2. my attempt results in the compiler error :
[BCC32 Error] Unit2.h(25): E2049 Class type 'TTaggedString' cannot be marked as __declspec(delphireturn)
  Full parser context
    Unit2.h(19): class TTaggedStringCan this be done ?

my code is as follows:
//header file
class TTaggedString : public AnsiString
{
      public:
    int tag;
    TTaggedString();
    ~TTaggedString();
};
//.cpp file

TTaggedString::TTaggedString() : AnsiString()
{
      tag = 0; //default
}
//---------------------------------------------------------------------------
TTaggedString::~TTaggedString()
{
}
0
Comment
Question by:alcindor
  • 2
  • 2
5 Comments
 
LVL 9

Expert Comment

by:rawinnlnx9
ID: 39835954
class TTaggedString : AnsiString

Drop the public from the AnsiString. It inherits the scope of it's parent.
0
 
LVL 2

Author Comment

by:alcindor
ID: 39835991
I tried that on BCB5 and XE2 compilers and the same error is given.
0
 
LVL 9

Expert Comment

by:rawinnlnx9
ID: 39835995
Oh! Hmm... I'll fire up C++ and give this a run.
0
 
LVL 86

Accepted Solution

by:
jkr earned 1500 total points
ID: 39836773
I'm afraid to state it seems you can't - for a reason as simple as it is important. See http://docwiki.embarcadero.com/RADStudio/XE5/en/The_declspec_Keyword_Extension 


 __declspec(delphireturn)

The delphireturn argument is for internal use only by the VCL in C++Builder. It is used for declarations of classes that were created in C++Builder to support Object Pascal built-in data types and language constructs, because they do not have a native C++ type. These include Currency, UnicodeString, AnsiString, Variant, TDateTime, and Set. The delphireturn argument marks C++ classes for VCL-compatible handling in function calls as parameters and return values. This modifier is needed when passing a structure by value to a function between Object Pascal and C++.

If you are trying to inherit from a class that has member which do not represent a native C++ type, it can't work.
0
 
LVL 2

Author Closing Comment

by:alcindor
ID: 39836830
Thanks for your help.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question