Solved

how to sub-class an AnsiString

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
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 be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

752 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