Thread View: gnu.g++.help
7 messages
7 total messages
Started by Arthur Cinader Jr
Mon, 04 Mar 1996 05:14
IS THIS LEGAL? Static method returns pointer to class
Author: Arthur Cinader Jr
Date: Mon, 04 Mar 1996 05:14
Date: Mon, 04 Mar 1996 05:14
40 lines
1505 bytes
1505 bytes
I may be going at this wrong, but I want to have a class
Triangle contain a static method called makeinstance. The
method will be passed a refernce to a Param object that has
a list of parameters for checking first and then passing to
the Triangle constructor.
The parameters are checked and if all is ok, a Triangle
instance is "newed" and the pointer to the new Trinagle is
returned. When I compile, I get the following error:
% g++ -c triangle.C
In file included from triangle.C:8:
triangle.h:17: syntax error before `*'
...
%
***The declaration for the class:
1 // triangle.h
2 // declaration of class Triangle extends shape
3
4 #ifndef TRIANGLE_H
5 #define TRIANGLE_H
6
7 #include "point.h"
8 #include "param.h"
9
10 class Trianlge : public Point {
11 public:
12 Trinagle(float = 0.0, float = 0.0, float = 0.0);
13 float gets() const;
14 virtual void draw() const;
15
16 static Param &getParams();
17 static Triangle *makeinstance(Param &);
18 private:
19 float side;
20 };
21
22 #endif
Re: IS THIS LEGAL? Static method returns pointer to class
Author: Noel Fegan
Date: Mon, 04 Mar 1996 11:10
Date: Mon, 04 Mar 1996 11:10
62 lines
2195 bytes
2195 bytes
acinader@panix.com (Arthur Cinader Jr) wrote:
>I may be going at this wrong, but I want to have a class
>Triangle contain a static method called makeinstance. The
>method will be passed a refernce to a Param object that has
>a list of parameters for checking first and then passing to
>the Triangle constructor.
>The parameters are checked and if all is ok, a Triangle
>instance is "newed" and the pointer to the new Trinagle is
>returned. When I compile, I get the following error:
>% g++ -c triangle.C
>In file included from triangle.C:8:
>triangle.h:17: syntax error before `*'
>...
>%
>***The declaration for the class:
> 1 // triangle.h
> 2 // declaration of class Triangle extends shape
> 3
> 4 #ifndef TRIANGLE_H
> 5 #define TRIANGLE_H
> 6
> 7 #include "point.h"
> 8 #include "param.h"
> 9
> 10 class Trianlge : public Point {
> 11 public:
> 12 Trinagle(float = 0.0, float = 0.0, float = 0.0);
> 13 float gets() const;
> 14 virtual void draw() const;
> 15
> 16 static Param &getParams();
> 17 static Triangle *makeinstance(Param &);
> 18 private:
> 19 float side;
> 20 };
> 21
> 22 #endif
The idea looks fine to me. However, if this is a direct copy of the code you
wrote you better mind your spelling. The word Triangle is spelled differently in
the three place it appears:
class Trianlge...
Trinagle(float....
static Triangle *makeinstance...
This would definitely cause the problem you described...
--
Noel Fegan
European Software Development Department
American Power Conversion
My views used to be my own, and then I got married...
I don't speak for APC...
nfegan@apcc.com
Re: IS THIS LEGAL? Static method returns pointer to class
Author: Shekar Ramanathan
Date: Mon, 04 Mar 1996 12:41
Date: Mon, 04 Mar 1996 12:41
34 lines
1550 bytes
1550 bytes
Arthur Cinader Jr (acinader@panix.com) wrote:
> The parameters are checked and if all is ok, a Triangle
> instance is "newed" and the pointer to the new Trinagle is
> returned. When I compile, I get the following error:
> % g++ -c triangle.C
> In file included from triangle.C:8:
> triangle.h:17: syntax error before `*'
> ...
> %
> ***The declaration for the class:
[...]
> 10 class Trianlge : public Point {
^^^^^^^^
If you included the exact code, the above typo may be the culprit.
And IMHO, I think a Triangle is not "is-a" Point but rather it is
composed of points. So I think Triangle should not inherit from Point.
Just a thought.
Shekar
--
---------------------------------------------------------------------
Shekar Ramanathan | mailto:shekar@CS.MsState.edu
Department of Computer Science | http://www.cs.msstate.edu/~shekar
Mississippi State University |
For the latest in World Cup Cricket, finger shekar@cs.msstate.edu
---------------------------------------------------------------------
Re: IS THIS LEGAL? Static method returns pointer to class
Author: Mickey Williams 66753
Date: Mon, 04 Mar 1996 17:36
Date: Mon, 04 Mar 1996 17:36
28 lines
1268 bytes
1268 bytes
In article <4hdu70$efa@panix.com>, acinader@panix.com (Arthur Cinader Jr) writes:
> 10 class Trianlge : public Point {
^^ Tri - a n g l e
> 11 public:
> 12 Trinagle(float = 0.0, float = 0.0, float = 0.0);
^^
> 13 float gets() const;
> 14 virtual void draw() const;
> 15
> 16 static Param &getParams();
> 17 static Triangle *makeinstance(Param &);
^^^^^^^^ This is the traditional spelling
> 18 private:
> 19 float side;
> 20 };
Trianlge, Trianagle, Triangle: pick one, and stick with it ;)
---
Mickey Williams
Ericsson Inc. Business Systems Division
+1 714 236-6753
The opinions above are mine alone, and not those of my employer...
Re: IS THIS LEGAL? Static method returns pointer to class
Author: Arthur Cinader Jr
Date: Mon, 04 Mar 1996 19:28
Date: Mon, 04 Mar 1996 19:28
7 lines
544 bytes
544 bytes
Thanks to all who pointed out my typos! I swear I checked for them and evenb after they were pointed out, I still had to hunt for them....? Guess I need glasses... Arthur
Re: IS THIS LEGAL? Static method returns pointer to class
Author: CHAMBERS Jason
Date: Tue, 05 Mar 1996 19:44
Date: Tue, 05 Mar 1996 19:44
61 lines
2484 bytes
2484 bytes
This is a multi-part message in MIME format.
---------------------------------19997724768799091920253434
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset=us-ascii
At line 10, surely Trianlge should be Triangle?
---------------------------------19997724768799091920253434
Content-Transfer-Encoding: 7bit
Content-Type: text/plain
From: acinader@panix.com (Arthur Cinader Jr)
Newsgroups: gnu.g++.help,comp.lang.c++
Subject: IS THIS LEGAL? Static method returns pointer to class
Date: 4 Mar 1996 00:14:08 -0500
Organization: Panix
Message-ID: <4hdu70$efa@panix.com>
I may be going at this wrong, but I want to have a class
Triangle contain a static method called makeinstance. The
method will be passed a refernce to a Param object that has
a list of parameters for checking first and then passing to
the Triangle constructor.
The parameters are checked and if all is ok, a Triangle
instance is "newed" and the pointer to the new Trinagle is
returned. When I compile, I get the following error:
% g++ -c triangle.C
In file included from triangle.C:8:
triangle.h:17: syntax error before `*'
..
%
***The declaration for the class:
1 // triangle.h
2 // declaration of class Triangle extends shape
3
4 #ifndef TRIANGLE_H
5 #define TRIANGLE_H
6
7 #include "point.h"
8 #include "param.h"
9
10 class Trianlge : public Point {
11 public:
12 Trinagle(float = 0.0, float = 0.0, float = 0.0);
13 float gets() const;
14 virtual void draw() const;
15
16 static Param &getParams();
17 static Triangle *makeinstance(Param &);
18 private:
19 float side;
20 };
21
22 #endif
---------------------------------19997724768799091920253434--
Re: IS THIS LEGAL? Static method returns pointer to class
Author: G. Patrick Sand
Date: Wed, 06 Mar 1996 19:56
Date: Wed, 06 Mar 1996 19:56
27 lines
1303 bytes
1303 bytes
In article <Dnt85t.FGu@doc.ntu.ac.uk>, pt3chaj says... [SNIP!!] > 17 static Triangle *makeinstance(Param &); [snip!--a smaller snip ;-)) Drop the * before the function name--what you have here is a pointer to a function (which is itself a pointer...) It should work fine if you just define it at: static Triangle makeinstance(Param &); I've used static functions to create objects, especially singletons, a la Design Patterns--Gamma, et al. Works like a charm... -- G. Patrick Sand psand@eos.hitc.com PatSand@aol.com (301) 925-0791 "Travel Light But Right..." Microsoft Network is prohibited from redistributing this work in any form, in whole or in part. License to distribute this individual post is available to Microsoft for $999. Posting without permission constitutes an agreement to these terms...gps
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads