🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #3757

Re: Basic C++ Question...

#3757
From: pnunn
Date: Fri, 05 May 2006 07:45
74 lines
3085 bytes
OK, still struggling with this one..

Here's the latest.

In base class..  struct stateLine *table;

In derived class axleTable = new struct stateLine[noLines];
    axleTable[0] = new stateLine(1 , High, Low, 2);
    axleTable[1] = new stateLine(1 , Low, High, 7);
    axleTable[2] = new stateLine(1 , Low, Low, 5);
    axleTable[3] = new stateLine(2 , Any, High, 3);

Then the idea is to send this pointer to the base class so it can be 
used there.

However,
This fails to compile with a couple of errors.
1. No default constructor for stateLine..

So, I provide one of these, then we get errors saying that you can't 
convert stateLine to stateLine *.

What am I doing wrong here?  Any help please.

ta.

Peter.

pnunn wrote:
> Folks.. I'm stuck on a problem that should be easy to sort out but I 
> can't get to work.
> 
> I have a base class defined that has a pointer to a structure in it.
> 
> struct stateTable *table;
> 
> and a public function setTable that takes a passed in pointer and sets 
> table to it...
> 
> In the derived class I have (in the constructor)
> 
>    struct stateLine binTable[] =
>    {
>        //current state, A0, A1, next state
>        {1, High, Low, 2},
>        {1, High, High, 4},
>        {1, Low, High, 5},
>        {2, Low, Low, 1},
>        {2, High, High, 4},
>        {4, High, Low, 3},
>        {3, Low, Low, 1},
>        {3, Low, High, 4},
>        {5, High, High, 4},
>        {5, Low, Low, 1}
>    };
> 
>    setTable(binTable);
> 
> Now.. when I go to use table in other functions.. table points to 
> nothing useful.. and I guess its because as binTable goes out of scope, 
> so does the memory its using... so I guess I can see why its not 
> working, but, I can't work out how to make it work.
> 
> If I have a stateTable* in the derived class, how do I dynamically make 
> the table and pass it to the base class?
> 
> I'd really rather build the table as the above code shows, but then how 
> do I pass that to the base class and have it still be there?
> 
> I know this is basic C++, but any help greatly appreciated.
> 
> Ta.
> 
> Peter.
Technical Details
Message-ID: <445b029d@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!news3.google.com!news2.volia.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <445a02bf$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,f15d7bde0eba2566
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
Date: Fri, 05 May 2006 17:45:33 +1000
From: pnunn <pnunn@infoteq.com.au>
User-Agent: Mozilla Thunderbird 1.0.6 (Windows/20050716)
X-Accept-Language: en-us, en
MIME-Version: 1.0
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Re: Basic C++ Question...
References: <445a02bf$1@newsgroups.borland.com>
In-Reply-To: <445a02bf$1@newsgroups.borland.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 144.137.61.115
Message-ID: <445b029d@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1146815133 144.137.61.115 (5 May 2006 00:45:33 -0700)
Lines: 74
Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!news3.google.com!news2.volia.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail