Solved

how to sub-class an AnsiString

Posted on 2014-02-05
5
459 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
Comment Utility
class TTaggedString : AnsiString

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

Author Comment

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

Expert Comment

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

Accepted Solution

by:
jkr earned 500 total points
Comment Utility
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
Comment Utility
Thanks for your help.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

762 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

6 Experts available now in Live!

Get 1:1 Help Now