473,597 Members | 2,437 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Inheriting Classes Across Files

In my program I need derived classes to inherit from the super class.

I can do this but I'd like to split the super class into it's own file.

How do you do this? When I split the code I start getting errors.

Jul 18 '05 #1
4 1254

"Tina" <bad_addy@no_do main.com> wrote in message
news:E6******** *******@newsrea d2.news.pas.ear thlink.net...
In my program I need derived classes to inherit from the super class.

I can do this but I'd like to split the super class into it's own file.

How do you do this? When I split the code I start getting errors.
The module with the superclass has to be imported before
the subclass is defined.

Be very careful you don't get into an import loop.
That way lies madness.

John Roth

Jul 18 '05 #2
I tried that as I understand it. I'm sure I'm making a silly error in all
this. Here is a simple example of what I'm trying:

--- (File super_class.py) ---

class base_class:

def sample():
return "Returned!"

--- (File sub_class.py) ---

import super_class

class derived_class(b ase_class):

def sample2():
return "Returned Twice!"

--- (End) ---

Traceback (most recent call last):
File "/home/tina/python/test/sub_class.py", line 3, in -toplevel-
class derived_class(b ase_class):
NameError: name 'base_class' is not defined
John Roth wrote:

"Tina" <bad_addy@no_do main.com> wrote in message
news:E6******** *******@newsrea d2.news.pas.ear thlink.net...
In my program I need derived classes to inherit from the super class.

I can do this but I'd like to split the super class into it's own file.

How do you do this? When I split the code I start getting errors.


The module with the superclass has to be imported before
the subclass is defined.

Be very careful you don't get into an import loop.
That way lies madness.

John Roth


Jul 18 '05 #3

"Tina" <bad_addy@no_do main.com> wrote in message
news:kn******** *******@newsrea d1.news.pas.ear thlink.net...
I tried that as I understand it. I'm sure I'm making a silly error in all
this. Here is a simple example of what I'm trying:

--- (File super_class.py) ---

class base_class:

def sample():
return "Returned!"

--- (File sub_class.py) ---

import super_class

class derived_class(b ase_class):

def sample2():
return "Returned Twice!"

--- (End) ---

Traceback (most recent call last):
File "/home/tina/python/test/sub_class.py", line 3, in -toplevel-
class derived_class(b ase_class):
NameError: name 'base_class' is not defined
That needs to be

class derived_class(s uper_class.base _class):
pass

or else:

import base_class from super_class

HTH

John Roth


John Roth wrote:

"Tina" <bad_addy@no_do main.com> wrote in message
news:E6******** *******@newsrea d2.news.pas.ear thlink.net...
In my program I need derived classes to inherit from the super class.

I can do this but I'd like to split the super class into it's own file.

How do you do this? When I split the code I start getting errors.


The module with the superclass has to be imported before
the subclass is defined.

Be very careful you don't get into an import loop.
That way lies madness.

John Roth

Jul 18 '05 #4
Tina:
Instead of "import super_class", I think you need
"from super_class import base_class", or
"from super_class import *", or if you want to use "import super_class",
then define the derived class as
"class derived_class(s uper_class.base _class)"

Mike
Tina wrote:
I tried that as I understand it. I'm sure I'm making a silly error in all
this. Here is a simple example of what I'm trying:

--- (File super_class.py) ---

class base_class:

def sample():
return "Returned!"

--- (File sub_class.py) ---

import super_class

class derived_class(b ase_class):

def sample2():
return "Returned Twice!"

--- (End) ---

Traceback (most recent call last):
File "/home/tina/python/test/sub_class.py", line 3, in -toplevel-
class derived_class(b ase_class):
NameError: name 'base_class' is not defined
John Roth wrote:

"Tina" <bad_addy@no_do main.com> wrote in message
news:E6****** *********@newsr ead2.news.pas.e arthlink.net...
In my program I need derived classes to inherit from the super class.

I can do this but I'd like to split the super class into it's own file.

How do you do this? When I split the code I start getting errors.


The module with the superclass has to be imported before
the subclass is defined.

Be very careful you don't get into an import loop.
That way lies madness.

John Roth

Jul 18 '05 #5

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

Similar topics

5
6877
by: Andy Jarrell | last post by:
I'm trying to inherit from a specific class that has an overloaded operator. The problem I'm getting is that certain overloaded operators don't seem to come with the inheritance. For example: // TestA.h --------------------------------------- #include <iostream> enum Aval { FIRST_VALUE,
1
2440
by: john diss | last post by:
hello there everyone.. I have created a class called "ProcessLog" inheriting from XmlDocument and two classes ("UploadedItem", "ProcessError") inheriting from XmlElement. I then have two classes ("UploadedTemplate", "UploadedPresentation") which inherit from "UploadedItem")... so far so good. I have overriden the CreateElement method of "ProccessLog" and it creates the correct elements as expected. The problem is I need to override...
2
2226
by: Peter Bates | last post by:
Hi, I'm just getting used to XSDObjectGen and i have the following question. Can i use a class inherited from a class generated by XSDObjectGen with XmlSerialize? Specifically, I have many xml files arriving from a PC inventory scanner we use. I wish to deserialize them and then process them.
6
6269
by: Russell Mangel | last post by:
Jeffery Richter makes the following statement in two books, the first was written in 2004, the latter in 2002. "You should not define new exception classes derived from ApplicationException; use Exception instead." ..NET Framework Standard Library Annotated Reference, Volume 1: Base Class Library and Extended Numerics Library (2004) http://www.aw-bc.com/catalog/academic/product/0,1144,0321154894-DS,00.html Exception Management...
2
9488
by: joye | last post by:
Hello, My question is how to use C# to call the existing libraries containing unmanaged C++ classes directly, but not use C# or managed C++ wrappers unmanaged C++ classes? Does anyone know how to do that? Thanks. Tsung-Yu
24
2932
by: toton | last post by:
Hi, I want to have a vector like class with some additional functionality (cosmetic one). So can I inherit a vector class to add the addition function like, CorresVector : public vector<Corres>{ public: void addCorres(Corres& c); //it do little more than push_back function. }
7
2495
by: Amu | last post by:
Hi i am stuck up in a part of project where i have to inherit the VC++ template classes into C#.net. Please provide me the solution for this .
5
1549
by: jc | last post by:
RE: Two Classes with the same Data Structure.. saving code? Inheriting a structure? I have two classes. One in Inherits System.Collections.CollectionBase, the other does not, but they both have the identical structure and properties. the only difference between them is there methods and that one is a collection class and the other is not. currently the code starts like this:
4
1688
by: AalaarDB | last post by:
struct base { int x, y, z; base() {x = 0; y = 0; z = 0;}; base(int x1, int y1, int z1) {x = x1; y = y1; z = z1;}; }; struct intermediate1 : public virtual base {}; struct intermediate2 : public virtual base
0
7883
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8263
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8021
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8254
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
5842
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3876
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2393
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1492
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1226
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.