Hello. We're going into Constructora and super, using extends, subclasses etc. I have this code: class Student { private String name; private String matric_no; public Student(String n, String m) { name = n; matric_no = m; } } class UndergradStudent extends Student { private String programme; public UndergradStudent(String n, String m, String p) { programme = p; super(n, m); } } class PostgradStudent extends Student { private String supervisor; public PostgradStudent(String s) { supervisor = s; } } and there is a compilation error in the subclasses. i understand that UndergradStudent inherits the private fields of Student but cannot do …

Member Avatar
Member Avatar
+0 forum 3

Using an initialization list for a class array variable, what do you use to setup a slot with a 3parameter Ctor?

Member Avatar
Member Avatar
+0 forum 1

Is there a way to require a subclass to call super explicitly in it's constructor?

Member Avatar
Member Avatar
+0 forum 4

Hi, As we know constructor doesn't have any return value so it is not good idea to perform exceptional handling inside constructor.SO i would like to know if i am opening a file inside constructor and due to some reason (file not exist) failure happened inside constructor then how to tackle this issue. so below are some questionin my mind (1) should we perform exceptional handling inside constructor. (2) if failure (file opening falure) happens inside constructor, does it going to affect the object state. I mean to say object is going to be currupted. if yes then what are …

Member Avatar
Member Avatar
+0 forum 17

Hey everyone, Got 2 questions here that i'm hoping will be answered. Say i have 2 variables int iValue; int iValueArray[300]; and later on init. them in the constructor Banana::Banana(): ival(0), ivalArray() {} 1. What would the ivalArray() indicate? Would it be the same as initializing every element to null/empty? Or does it actually mean something else such as every element is init. to 0? 2. I've always initialized variables in constructors like Banana::Banana() { iValue = 0; ... } is there a difference between initializing after a colon and before the {} and initializing inside the {}. I understand …

Member Avatar
Member Avatar
+0 forum 4

Hello programmers! I have been working on a hardware store application, where there is a `HardwareRecord`class that stores information about each object in a store (ex: nuts, bolts, screws, and so forth). Here's my declaration of this class: // HardwareRecord.h // Initialize Hardware Store File // // // Definition of HardwareRecord class #ifndef __Initialize_Hardware_Store_File__HardwareRecord__ #define __Initialize_Hardware_Store_File__HardwareRecord__ #include <iostream> class HardwareRecord { public: HardwareRecord(int=0,std::string="",std::string="",double=0.); //constructor explicit HardwareRecord(); HardwareRecord operator=(HardwareRecord&); //'set' and 'get' functions void setAccountNumber(int); int getAccountNumber() const; void setName(std::string); std::string getName() const; void setPrice(double); double getPrice() const; void setDescription(std::string); std::string getDescription() const; void wipeRecord(); //set everything to blank private: int …

Member Avatar
Member Avatar
+0 forum 33

Hi guys, I have small problem with my example code. Any hint? #include <iostream> using namespace std; class A{ public: int a; A(int i){a = i;} A(const A& rhs) // copy constructor { a = 2; } A(const A&& rhs) // move constructor { a = 3; } }; void print(A a) { cout << a.a << endl; } A createA() { A a(1); return a; } int main(){ A a = createA(); print(a);// This will invoker copy constructor and output is 2 print(createA()); // This should invoke move constructor because this object here is rvalue right? } Output is: …

Member Avatar
Member Avatar
+0 forum 6

You cannot determine whether a ctor is being called on an object that is to become const. Such as: const Foo bar( another_foo ); // no way to determine in the ctor that bar will be const I'd like some sort of function attribute for copy constructors to determine if \*this is being constructed as const. Particularly for clases that share pointers to resources. A const ctor would make perfect sense if it were feasible to be implemented into the standard in this way. we shouldn't have to create whole new classes for this kind of functionality, such as with …

Member Avatar
+0 forum 0

hi, done some work is not finished yet but this two versions\stages are runable. and what is very helpfull, to read opinion, suggestion, critic, ideas, feelings about. here is the link: http://softwareconstructor.webs.com/ and i need to read what u think about two firsts: * tryout2 (10bm) * and tryout1 (190mb) (there are 3links for each may chose, not every need registering to download) thanks

Member Avatar
Member Avatar
+0 forum 1

Okay so inside my ArcherArmor.cpp, I'm trying to figure out why the map initializer list isn't working, but for some reason I keep getting "Error C2593: 'operator =' is ambiguous". Here is my code: I also have a class which ArcherArmor is derived from, that has a struct called `Armor`, which I left out for simplicity. The main problem is that error! The only thing I can think of is that im initializing the map wrong. //ArcherArmor.h #include <string> #include <map> class ArcherArmor { private: map <int, Armor> soldier_armor; public: void ArcherArmor_shop(); }; //ArcherArmor.cpp #include "ArcherArmor.h" void ArcherArmor::ArcherArmor_shop(){ soldier_armor = …

Member Avatar
Member Avatar
+0 forum 5

Hi, I do have doubt regarding const declaration in copy constructor. Can anyone let me know why do we need const reference in copy constructor, as we already know reference itself is const pointer.So why we should use const as a prefix in copy constructor. Regards, Mohan

Member Avatar
Member Avatar
+0 forum 4

I'm trying to create a list stack that implements some interface called SomeList The list stack should only use stack with no links. the itnerface has a number of methods that I would like to implement. So for SomeList I have something like public interface SomeList<T>{public void plus(T something);public E takeout(int somewhere); and so on} For the generic ListStack I have something like public class ListStack<T> implements SomeList<T>{ Stack<T> stack1=new Stack<E>(); //constructor public LinkStack(){ stack1=new Stack<T>(); } //method public void plus(T somethig){ this.push();} . . . } In the method above (plus(T something)) I get an error on push. Eclipse …

Member Avatar
Member Avatar
+0 forum 13

Hi, Is there any way to not allow private construction in friend function, In case we do have private constructor with friend function in our class.Only Static method should be responsible for object creation and other than this compiler should flash error message. #include<iostream> #include<memory> using namespace std; class a { public: void see () { cout<<"Motimaa"; } static a& getinstance() { static a instance; return instance; } private: a() {}; friend void access(); }; void access () { a obj; obj.see();//still friend function can access } int main() { a::getinstance().see(); access(); return 1; }

Member Avatar
Member Avatar
+0 forum 4

I'm having trouble pinpointing the exact definition of a generic linkedstack class Suppose I have public class LinkedStack<T> { //some variables //would this be right LinkedStack(){ } //for a generic constructor of type T for the LinkedStack class of type T? }

Member Avatar
Member Avatar
+0 forum 1

Ques : Define the class Book with all the basic attributes such as title, author, publisher, price etc. Define the default constructor, member functions display_data() for displaying the Book details. Use appropriate access control specifiers in this program I have done some part #include<iostream.h> #inlude<conio.h> using namespace std; class book { char author, publisher, price ,ibn; of the program .. but i am not getting the concept of Default contructor .. Please help me in understanding it by giving an example .. it to complicated as i have readd on stackoverflow.com , on ibm website and other websites also .. …

Member Avatar
Member Avatar
+0 forum 9

class name { char *s; int len; public: name(){ // Default constr. s=NULL; len =0; } //************************************************** ~name(){ // Destruct. if (s!=NULL){ delete [] s; s=NULL; } } //************************************************* name(const char * s1); // Constr. char* getName(); //fcn get name int getLen() ; // fcn get lenght void setName(const char * s1); // fcn set name }; void name::setName(const char * s1){ if (s!=NULL){ delete [] s; s=NULL; } len = strlen(s1)+1; s=new char [len]; // back*** strcpy(s,s1); } name::name(const char * s1){ if (s!=NULL){ delete [] s; s=NULL; } len = strlen(s1)+1; s=new char [len]; // back*** strcpy(s,s1); } …

Member Avatar
Member Avatar
+0 forum 5

am a python beginner, receeently started learning about classesand i wrote this got this little code that keeps bringing this error . please i need someone here to help debug it: class employee(): ` empcount=0` def _init_(self,name,salary): self.name=name self.salary=salary employee.empcount=+1 def displaycount(self): print 'Total employee: %d' %employee.empcount def displayemployee(self): print 'Name:',self.name,'salary:',self.salary ######################################################### #main program emp1n=raw_input('enter name of employee1:') emp2n=raw_input('enter name of employee2:') emp1s=input('enter salary of employee1:') emp1n=input('enter salary of employee2:') emp1=employee(emp1n,emp1s) emp2=employee(emp2n,emp2s) emp1.displayemployee() emp2.displayepmloyee() print 'total employees:',employee.empcount

Member Avatar
Member Avatar
+0 forum 4

Hi, Please tell me in the following question why no copy constructor is called when fun returns the A object. While returning b and constructing c, there is no copy constructor called. Why?? #include<iostream> using namespace std; class A { public: A(){cout <<"Default\n";} A(const A&){ cout<<"copy\n"; } A fun(A a) { A b; return b; } }; int main() { A a; A c = a.fun(a); // Here atleast copy copy constructor should have been called. return 0; }

Member Avatar
Member Avatar
+0 forum 2

why constructor don't have return type

Member Avatar
Member Avatar
+0 forum 3

Hi All I have a query regarding constructor and destructor. How accessibility of constructor and destructor affects the scope and the visibility of their class. If someone give some explaination on this I will be thankful. Regards

Member Avatar
Member Avatar
+0 forum 4

I need to write a code with a constructor class in order to see the whole phonelist using an array that reads from a document txt, able to add a person and phone number, search just one person in the phonelist and able to modify their phone number. here is my code Constructor: public class PhoneBookEntry { private String name; private String phone; public void setName(String n){ name=n; } public void setPhone(String p){ phone=p; } public String getName(){ return name; } public String getPhone(){ return phone; } public String toString(){ String str = "name " + name + "\n phone" …

Member Avatar
Member Avatar
+0 forum 14

I am having a problem to understand how class inhertance works in Java.. Now I want to get information from a class to another and let's say we have class A and class B class A contains a string an int and a byte class B contains a String and an int but class A contains a constructor that have values set and based on a method what I am trying to do is pass and add the values of class A and B together in one new constructor that is based on the constructor that is initlized in class …

Member Avatar
Member Avatar
+0 forum 5

For example let's say we have the property called Customer that returns a value of name String name; <== Global Variable public String getName() { return name; } public String setName(holdingName) { name=holdingName; } and a constructor called Match public FullName(String realName) { holdingName = realName; } Can I do what I have done up there? I know it does not work, but is there any way to make it work? Please let me know if you need further information to get this question answered.. Thank you

Member Avatar
Member Avatar
+0 forum 7

So I am working on a program and it has two seperate classes.. One of them contain the forum layout and the other contain some calculations and totals.. The problem is that the class with the calculations contain a constructor and other functions that I need to pass from this class to the other one (the forum), I don't know how to pass these values and functions, and is it possible to do so? Thank you

Member Avatar
Member Avatar
+0 forum 4

Hi all! I just have a quick question about the execution of a copy constructor. This is the code i'm testing my work with as I'm busy learning for a test. Class file: Clock :: Clock (int h, int m, int s) { hr = h; min = m; sec = s; cout << " Default constructor " << endl ; } Clock :: Clock ( const Clock & c) { hr = c.hr; min = c.min ; sec = c.sec ; cout << " Copy constructor " << endl ; } Clock Clock :: LunchTime () { hr = …

Member Avatar
Member Avatar
+0 forum 3

Hi! I am supposed to write a programm for making a window.First of all, I must make a window with some given default values. Below is the code that I have been given as a template public class Window { private String name; private int height; private int width; private String isActive; private String color; int[] WindowPoint=new int[2]; public Window() { name="MyWindow"; height=6; width=12; WindowPoint[0] =0; WindowPoint[1] =0; color="white"; isActive="active"; } There's something that I cannot understand: In order to make a window, shouldn't I import the JFrame package and say that the Window class is a subclass of JFrame? …

Member Avatar
Member Avatar
+0 forum 5

Hi everyone! So I have this code to modify. I need to write a code inside the **int main** field, that would cause 37 launches of the constructor called M_48(). I have no idea how to solve this. Any ideas?

Member Avatar
Member Avatar
+0 forum 5

So this is basically what's supposed to be the outcome of my code: > 69:hw/05/src> javac WordOccurrenceCounter.java 70:hw/05/src> java WordOccurrenceCounter Reading the book... Getting counts from a TreeMap... Enter a string ('q' to quit): wealth wealth occurred 7 times. Enter a string ('q' to quit): poverty poverty occurred 10 times. Enter a string ('q' to quit): pestilence pestilence occurred 1 times. Enter a string ('q' to quit): man man occurred 1193 times. Enter a string ('q' to quit): woman woman occurred 230 times. Enter a string ('q' to quit): unix unix occurred 0 times. Enter a string ('q' to quit): …

Member Avatar
Member Avatar
+0 forum 2

Hey, I'm developing a program in which there are two classes. The purpose of one of them is to create vectors that change dinamically (class A) and the other is a bunch of methods to operate on these vectors (class B). The question is: I don't see any need to define a constructor in class B. In fact, I just define an object of class B, in main(), to access to the methods within it. Is there any problem to not define a constructor, but using an object to just access to those methods? Thanks

Member Avatar
Member Avatar
+0 forum 3

i Always getting : **mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\class\function.php on line 28** please give the suggestion friends config.php <?php define('DB_SERVER', 'localhost'); define('DB_USERNAME', 'root'); define('DB_PASSWORD', '12345'); define('DB_DATABASE', 'class'); class db_class { function db_constractor() { $connection = mysql_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD) or die('Oops connection error -> ' . mysql_error()); mysql_select_db(DB_DATABASE, $connection) or die('Database error -> ' . mysql_error()); } } ?> finction.php <?php include_once 'config.php'; class user { public function db_constractor() { $db = new db_class(); } public function register_user($name, $username, $password, $email) { $password = md5($passowrd); $sql = mysql_query("SELECT uid from users WHERE username ='$username' …

Member Avatar
Member Avatar
+0 forum 2

The End.