Solved

how to sub-class an AnsiString

Posted on 2014-02-05
5
547 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

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…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
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.

623 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