473,396 Members | 1,827 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.

abstract base class - how to initialize variables in derived?

ali
Hi,

I have a question with regards to abstract classes (understanding that
I cannot instantiate an abstract class).

If my Abstract base class has:

private:
int width;
int height;

How do I initialize/give values to these from my derived class? I
tried adding public methods to the base class, such as setWidth() and
setHeight(), and use them in the constructor of the derived class. Is
that a good solution? Is there any other method I can use?

I know that I cannot access base::height and base::width from the
derived class as they are private variables.

Thanks,

Ali

Feb 27 '07 #1
2 6316
On Feb 26, 9:27 pm, "ali" <aliasger.jaf...@gmail.comwrote:
Hi,

I have a question with regards to abstract classes (understanding that
I cannot instantiate an abstract class).

If my Abstract base class has:

private:
int width;
int height;

How do I initialize/give values to these from my derived class? I
tried adding public methods to the base class, such as setWidth() and
setHeight(), and use them in the constructor of the derived class. Is
that a good solution? Is there any other method I can use?
Use the base class' constructor.

class ABC {
//...
protected: // or public: if appropriate
ABC (int w, int h):
width (w), height (h) {
}

private:
int width;
int height;
};

class Concrete : public ABC {
public:
Concrete ():
ABC(0, 0) {
}
// ...

Feb 27 '07 #2

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

Similar topics

1
by: yan | last post by:
Hi, everybody. I'm new to this great forum, so hello! I start with a problem of my project. I have an Abstract Base Class used as base class for differentes Derived classes. The derived classes...
7
by: Jef Driesen | last post by:
Suppose I have an abstract base class that looks like this: template <typename T> class base { public: // Typedefs typedef double value_type; typedef std::size_t size_type; public: //...
8
by: Dev | last post by:
Hello, Why an Abstract Base Class cannot be instantiated ? Does anybody know of the object construction internals ? What is the missing information that prevents the construction ? TIA....
7
by: Baski | last post by:
Base class: class AssetBase { string _clli; public string CLLI { get
5
by: Lee Crabtree | last post by:
More fun wrapping unmanaged code... I have a class heirarchy that I need to expose to C#, so I need to wrap all the classes. That's not a big deal, except for the base class, which is abstract....
5
by: Roy Smith | last post by:
I want to have three classes; Parent, Child1, and Child2. Parent is to be an abstract base class with Child1 and Child2 concrete classes derived from Parent. Normally, to do that, Parent would...
1
by: D Witherspoon | last post by:
Coming up with a scenario here. For example there is the standard .NET MailMessage class. I am creating a project (let's call it CommonBase) that has the following 2 classes ...
14
by: junw2000 | last post by:
Is it possible to create an abstract base class without a pure virtual function? Thanks Jack
0
by: emin.shopper | last post by:
I had a need recently to check if my subclasses properly implemented the desired interface and wished that I could use something like an abstract base class in python. After reading up on metaclass...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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:
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...

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.