Solved

how to sub-class an AnsiString

Posted on 2014-02-05
5
476 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 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

864 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now