bugGNU Octave - Bugs: bug #46718, Unable to create classes

 
 

bug #46718: Unable to create classes

Submitter:  None
Submitted:  Sat 19 Dec 2015 02:04:31 PM UTC
   
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Works For Me Assigned to:  None
Originator Name:  Gadi Lahav Originator Email:  -email is unavailable-
Open/Closed:  * Closed Release:  * 4.0.0
Operating System:  * GNU/Linux Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Tue 14 Nov 2023 01:40:00 PM UTC, comment #9: 

Just point on the parent directory of the one you will adjoint to the path (visible on the top left window) and run:

>>addpath ("MyDirectoryName") 


then

>> p =polynomials([1,0,0])



comment #8:

> I know that this bug report is quite old, but I tripped on it today (January 2023) and maybe my experience can help someone else.
>
> As said, the constructor function must have the same name of the class and must belong to a directory whose name is the class name prefixed by '@' (e.g., '@polynomial/polynomial.m').
>
> In my case the error was caused by the fact that I added the '@'-directory to the path.  The '@' directory must be in a directory in the search path list, but it *must not* be in the path list itself.
>
> To clarify: if you added the directory '@polynomial' in `~/my-octave-lib` you must do
>
> addpath ~/my-octave-lib
>
> but NOT 
>
> addpath ~/my-octave-lib/@polynomial
>

Anonymous
Thu 12 Jan 2023 02:53:55 PM UTC, comment #8: 

I know that this bug report is quite old, but I tripped on it today (January 2023) and maybe my experience can help someone else.

As said, the constructor function must have the same name of the class and must belong to a directory whose name is the class name prefixed by '@' (e.g., '@polynomial/polynomial.m').

In my case the error was caused by the fact that I added the '@'-directory to the path.  The '@' directory must be in a directory in the search path list, but it *must not* be in the path list itself.

To clarify: if you added the directory '@polynomial' in `~/my-octave-lib` you must do

addpath ~/my-octave-lib

but NOT 

addpath ~/my-octave-lib/@polynomial

Anonymous
Mon 07 Nov 2016 06:04:39 PM UTC, comment #7: 

This is a working example for the polynomial class. There is nothing wrong with, you just must to use it correctly.

https://savannah.gnu.org/support/download.php?file_id=38899

addons_zz <addons_zz>
Mon 07 Nov 2016 06:03:14 PM UTC, comment #6: 
addons_zz <addons_zz>
Mon 07 Nov 2016 05:22:35 PM UTC, comment #5: 


Creating classes

To create a class you need to make a folder prefixed with the symbol @. Inside the folder you need to create the constructor which is a function with the same name as the folder. For example, a class called dummy will be created in the folder @dummy and inside we should find a function (a method) dummy.m. The minimal content of this method is.

http://wiki.octave.org/Object_oriented_programming


addons_zz <addons_zz>
Mon 28 Dec 2015 05:06:32 PM UTC, comment #4: 

Are you getting this problem when the polynomial.m file is correctly put in a @polynomial directory which is a subdirectory of the current directory?

Mike Miller <mtmiller>
Group Member
Sun 27 Dec 2015 01:10:20 AM UTC, comment #3: 

I'm also getting the same problem while trying  to run the polynomial example.  I recently removed my octave and replaced it with a new copy of Octave-4.0_0.  I'm running it on a Windows 10 machine. 

As a test of creating a used a class out of the control package and got the following correct response:

>> pkg load control
>> h = filt([0,3],[1,4,2])


Transfer function 'h' from input 'u1' to output ...

            3 z^-1
 y1:  -------------------
      1 + 4 z^-1 + 2 z^-2

Sampling time: unspecified
Discrete-time model.

Delbert Johnson <del_johnson>
Mon 21 Dec 2015 01:54:14 PM UTC, comment #2: 

I get the same error message as the OP if I create polynomial.m as a function file on the path, rather than in a @polynomial subdirectory of the path.

The error message could perhaps say something a little more helpful to the user.

Mike Miller <mtmiller>
Group Member
Sat 19 Dec 2015 04:11:27 PM UTC, comment #1: 

Your polynomial code below is the same as examples/code/@polynomial/polynomial.m from the source tree which works fine for me.

Have you called your file polynomial.m and is it located in a @polynomial/ directory?

Try to change your current path (you can show it with pwd) wit cd so you see the @polynomial directory.

Andreas Weber <andy1978>
Group Member
Sat 19 Dec 2015 02:04:31 PM UTC, original submission:  

Originally, I started out building a class for my own purposes, but I kept getting the following error:


error: class: 'CComponent' is invalid as a class name in this context
error: called from
    CComponent at line 19 column 7
    test_CComponent at line 8 column 6


So I went on and tried the tutorial on the web\documentation:


function p = polynomial (a)
if (nargin == 0)
  p.poly = [0];
  p = class (p, "polynomial");
elseif (nargin == 1)
  if (strcmp (class (a), "polynomial"))
    p = a;
  elseif (isvector (a) && isreal (a))
    p.poly = a(:).';
    p = class (p, "polynomial");
  else
    error ("polynomial: expecting real vector");
  endif
else
  print_usage ();
endif
endfunction


Invoked it by simply writing

>> p = polynomial([1,0,1]);


Got the same error:

error: class: 'polynomial' is invalid as a class name in this context
error: called from
    polynomial at line 10 column 14


Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #38899:  polynomial.zip added by addons_zz (720B - application/octet-stream - This is a working example for the polynomial class. There is nothing wrong with, you just must to use it correctly.)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by addons_zz (Posted a comment)
  • -email is unavailable- added by del_johnson (Posted a comment)
  • -email is unavailable- added by mtmiller (Posted a comment)
  • -email is unavailable- added by andy1978 (Posted a comment)
  • -email is unavailable- added by None (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2016-11-07 addons_zz Attached File- Added polynomial.zip, #38899
    2016-02-22 mtmiller Open/ClosedOpen Closed
    2015-12-19 andy1978 StatusNone Works For Me

    Back to the top

    Powered by Savane 3.13-02a9.
    Corresponding source code