473,396 Members | 1,812 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Setting up a class

Using Borland Builder 5 I am trying to get a very simple first working
use of a class to work. Following the example of the OU course MT262
as nearly as I can, I have Created files named Class First,
ClassSecond, and ClassThird. And it's still wrong!
It is a windows application, but I don't think that's relevant.
ClassFirst.cpp
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop
USERES("ClassFirst.res");
USEFORM("ClassFirstU.cpp", Form1);
USEFORM("ClassSecond.cpp", Frame1); /* TFrame: File Type */
USEUNIT("ClassThird.cpp");
USEUNIT("ClassSecond.cpp");
//---------------------------------------------------------------------------
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
try
{
Application->Initialize();
Application->CreateForm(__classid(TForm1), &Form1);
Application->Run();
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
return 0;
}
//-------------------------------------

ClassFirstU.h

//---------------------------------------------------------------------------

#ifndef ClassFirstUH
#define ClassFirstUH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include "ClassSecond.h"
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TEdit *Box;
TEdit *Operator;
TEdit *Show1;
TEdit *Input1Box;
TLabel *Label1;
TLabel *Label2;
TLabel *Label3;
TEdit *Show2;
TEdit *ShowProduct;
TLabel *Label4;
TLabel *Label5;
TLabel *Label6;
TLabel *Label7;
TButton *ShowButton;
TButton *EnterInput1Button;
TButton *EnterInput2Button1;
TButton *MultiplyButton;
void __fastcall EnterInput1ButtonClick(TObject *Sender);
private: // User declarations
int Input1;
int Input2;
int Product;
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif

ClassFirstU.cpp

//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "ClassFirstU.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::EnterInput1ButtonClick(TObject *Sender)
{
Input1 = Input1Box ->Text.ToInt();
Show1->Text = Input1;
}

//---------------------------------------------------------------------------

ClassSecond.h

#define ClassSecondH
#include "ClassThird.h"
//---------------------------------------------------------------------------
class NumberBoardClass
{
protected:
NumberBoardType Board();
NumberBoardType ShowOne();
NumberBoardType Multiply(void);
public:
NumberBoardType Show();
};
#endif

ClassSecond.cpp

//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "ClassSecond.h"

//---------------------------------------------------------------------------
NumberBoardType NumberBoardClass::Multiply(void)
{
int LocalNumber;
LocalNumber = NumberBoardType.Input1 * NumberBoardClass.Input2;
NumberBoardType.Product = LocalNumber;
return Board;
}
#pragma package(smart_init)

ClassThird.h

//---------------------------------------------------------------------------

#ifndef ClassThirdH
#define ClassThirdH
//---------------------------------------------------------------------------
struct NumberBoardType
{
int Input1;
int Input2;
int Product;
};
#endif
ŒŒŒŒŒŒŒŒŒŒŒŒŒŒŒ..
And the error messages I get are :-
[C++ Error] ClassSecond.cpp(12): E2108 Improper use of typedef
'NumberBoardType'

[C++ Error] ClassSecond.cpp(12): E2108 Improper use of typedef
'NumberBoardClass'

[C++ Error] ClassSecond.cpp(13): E2108 Improper use of typedef
'NumberBoardType'

[C++ Error] ClassSecond.cpp(14): E2235 Member function must be called
or its address taken

I really don't know what's wrong!

Michael Bell

--
Nov 1 '07 #1
5 2989
Michael Bell wrote:
Using Borland Builder 5 I am trying to get a very simple first working
use of a class to work. Following the example of the OU course MT262
as nearly as I can, I have Created files named Class First,
ClassSecond, and ClassThird. And it's still wrong!
It is a windows application, but I don't think that's relevant.
ClassFirst.cpp
//---------------------------------------------------------------------------
[..lots of irrelevant cruft removed..]
#endif
OOOOOOOOOOOOOOO..
And the error messages I get are :-
[C++ Error] ClassSecond.cpp(12): E2108 Improper use of typedef
'NumberBoardType'
Apparently you defined 'NumberBoardType' as a typedef (to what? you
didn't show), and then are trying to use the same name to define
a class or something.
>
[C++ Error] ClassSecond.cpp(12): E2108 Improper use of typedef
'NumberBoardClass'
Same here.
>
[C++ Error] ClassSecond.cpp(13): E2108 Improper use of typedef
'NumberBoardType'
Same here.
>
[C++ Error] ClassSecond.cpp(14): E2235 Member function must be called
or its address taken
Most likely you use wrong syntax (like 'object.func', without the
following parens, or 'type::member' without the preceding '&'), but
there is no way to be certain because you didn't post the code that
gives you the error, you posted some other code, which is full of
non-standard constructs which prevents us from trying to compile it.
I really don't know what's wrong!
Whole lot of things, probably. No way to know for sure. See the
FAQ, section 5 ("How to Post").

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Nov 1 '07 #2
On 2007-11-01 13:34, Michael Bell wrote:
Using Borland Builder 5 I am trying to get a very simple first working
use of a class to work. Following the example of the OU course MT262
as nearly as I can, I have Created files named Class First,
ClassSecond, and ClassThird. And it's still wrong!
Your first problem is that the "very simple first working use of a
class" is very complex (at least for being simple use of classes). Your
second problem is that whatever material MT262 uses it is not very
portable and contains much stuff that is specific to that material
(Borland specific perhaps?). If I were you and had the choice I would
pick up a gooc C++ book and use that instead.
It is a windows application, but I don't think that's relevant.
That is very relevant, since third part libraries are off-topic in this
group and will limit the amount of help you can expect.

NumberBoardType NumberBoardClass::Multiply(void)
{
int LocalNumber;
LocalNumber = NumberBoardType.Input1 * NumberBoardClass.Input2;
Here you use NumberBoardType as if it was an object, but it is a type
(as defined below). You need to create an object of type NumberBoardType
and perform the operations on that.
struct NumberBoardType
{
int Input1;
int Input2;
int Product;
};
--
Erik Wikström
Nov 1 '07 #3
In message <zz*****************@newsb.telia.net>
Erik Wikström <Er***********@telia.comwrote:
[snip]

>NumberBoardType NumberBoardClass::Multiply(void)
{
int LocalNumber;
LocalNumber = NumberBoardType.Input1 * NumberBoardClass.Input2;
Here you use NumberBoardType as if it was an object, but it is a type
(as defined below). You need to create an object of type NumberBoardType
and perform the operations on that.
>struct NumberBoardType
{
int Input1;
int Input2;
int Product;
};
So, I ought to declare NumberBoardType as an object. How do I do that?

Michael Bell

--
Nov 1 '07 #4
Michael Bell wrote:
In message <zz*****************@newsb.telia.net>
Erik Wikström <Er***********@telia.comwrote:
[snip]

>>NumberBoardType NumberBoardClass::Multiply(void)
{
int LocalNumber;
LocalNumber = NumberBoardType.Input1 * NumberBoardClass.Input2;
>Here you use NumberBoardType as if it was an object, but it is a type
(as defined below). You need to create an object of type
NumberBoardType and perform the operations on that.
>>struct NumberBoardType
{
int Input1;
int Input2;
int Product;
};

So, I ought to declare NumberBoardType as an object. How do I do that?
class SomeClass {};
...
SomeClass an_object;

What is it you're trying to accomplish? Maybe you need to define a data
member in your 'NumberBoardClass'?

Also, consider that 'NumberBoardType' and 'NumberBoardClass' are WAAAAY
too similar for a casual reader to discern any difference between them.
Your naming can surely be improved.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Nov 1 '07 #5
On Thu, 01 Nov 2007 14:15:50 GMT, Michael Bell
<mi*****@beaverbell.co.ukwrote:
>In message <zz*****************@newsb.telia.net>
Erik Wikström <Er***********@telia.comwrote:
>>struct NumberBoardType
{
int Input1;
int Input2;
int Product;
};

So, I ought to declare NumberBoardType as an object. How do I do that?
No. Read what is there. The code above decares that there is a
struct (or class - nearly the same thing) called NumberBoardType.
That's fine. Now you need to create an _object_ of that type -
perhaps:

struct NumberBoardType MyNBT;

Now you can use that _object_:

MyNBT.Input1 = valueA;
MyNBT.Input2 = valueB;
etc.
--
PGP key ID 0xEB7180EC
Nov 1 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: DexHex | last post by:
Hi, I am stumpt. Is there anyway to set the background image on a webpart title?
4
by: ttan | last post by:
Hello, I'm writing a C# program on setting security for domain controller. what's a function call or class that apply for the security setting? is there a sample code? Here are the list of...
3
by: Patient Guy | last post by:
Subject line would seem to say it all: How does one trigger the execution of a method within an object or any other code/function with the setting of an object property? More elaboration for...
1
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
7
by: Ronald S. Cook | last post by:
In a .NET Windows app, if I set somehting like the title of the form to "MyApp" at run-time, will that make the app run slightly slower than if I had set the title at design-time? Thanks, Ron
7
by: Academic | last post by:
What are the different effects of the following two statements: C1.Cursor = Cursors.WaitCursor C1.Cursor.Current = Cursors.WaitCursor I believe the first replaces the entire C1.Cursor...
2
by: Avinash | last post by:
I have a class defined as follows: class main { ........ protected: another_class *obj; public: void set_another_class(another_class *ptr);
3
by: kjell | last post by:
Hi, I wonder if someone may have a solution to a small problem I'm experiencing with a C++ program? I'm have two classes in my application that provides methods for setting parameters in the...
2
by: Ronald S. Cook | last post by:
In my solution, I have a client (Windows app) and a class library. The class library project has a connection string setting that I would like to be able to change (from the client project...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.