473,378 Members | 1,478 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,378 software developers and data experts.

Inheritance and enum

13
Hello

Does anyone have a suggestion how to solve this in a better way?

I have an abstract class A containing an std::vector<> of Mat (other class; not important here), with an enum specifying what sort of information the vector holds at each index.


class A {

public:
enum matIndex {

goalA = 0,
goalP,
weightP,
weightG,

nrIndexes
};

protected:
std::vector<Mat> matrices;

public:
A();
Mat& getMat(matIndex i) { return matrices[i]; }
// lots of other functions
virtual void foo() = 0;

};

There are concrete classes inheriting from it, so the whole thing is pretty big.

Now I need another class B that's the same, except the enum is different (also different size). So I just copied A and inheriting classes and changed the names and enum, which works.

But now every time I change something, I have to change it in both places. Does anyone see a better method of doing this?

For example, if it was possible to define the enum at run-time in the constructor of the class (I know it isn't), my problem would be solved, just give an argument there.
Nov 29 '07 #1
1 3879
weaknessforcats
9,208 Expert Mod 8TB
Is it not possible to use the scope resolution operator:
Expand|Select|Wrap|Line Numbers
  1. if (data == B::NOPE || A::NOPE)
  2. etc...
  3.  
??
That way A's enum could have the common values and B enum could have the additions and if the two conflicted (as above) you could just identify whose enum to use.
Nov 29 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Thomas Matthews | last post by:
Hi, I have three classes: Category Author Publisher Each of these classes stores its information into a database table of <ID, text>. (They are fields that have a foreign key.) There is...
2
by: Alexander Lurye | last post by:
Hi! I have the following problem: Suppose that we have the following class: class A; class AException {
3
by: Matteo Settenvini | last post by:
Mmmh... I was trying some code, and I bumped in a strange behaviour. The following piece of code compiles normally : //////// CODE STARTS ///////////////// #include <iostream> class B {...
30
by: Vla | last post by:
why did the designers of c++ think it would be more useful than it turned out to be?
9
by: Joe | last post by:
Hello All: I work at an insurance company and we are changing the design of an ASP.NET application (for those have followed my postings, we're going to redesign some parts of the application -...
2
by: Richard Myers | last post by:
Howdy, I haven't struck this before.... I am visually inheriting several forms from another. All works well but then i thought i'd create an enum that is used only by this form - not even its...
1
by: FefeOxy | last post by:
Hi, This is a hypothetical thing that I want to test out, and if it works, I will be using it to enhance my code. // --- Suppose I have an abstract base class: --- class A { public:...
1
by: David Welch | last post by:
Hi, I have a bit of code where I am relying on empty base member optimisation. The bit of code is below: template<typename Enum> struct EncodePrefix { template<Enum e> struct Apply
1
by: Imre | last post by:
Hi I'd like to create a special cast template function that can be used to cast a base pointer to a derived one, and uses dynamic_cast if virtual inheritance is involved, and static_cast...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.