C++ :: Shape Class Polymorphism Compiler Error

Dec 10, 2014

Having issues with program to create a shape area calculator with circle square and rectangle. the uml goes as follows:

Where the UML has shape as the abstract class with public area():double, getName():string,and getDimensions:string, rectangle derived from shape with protected height, and width, and a public rectangle(h:double, w:double), followed by a derived square from rectangle with just a public square(h:double), and finally a circle derived from shape with a private radius, and a public circle(r:double).

[URL]

Have linked my program and it is giving me the following compiler errors:

error: 'qdebug' was not declared in this scope line 15 of main

error: cannot declare variable 'shp' to be of abstract type 'shape' line 22 of main

error: expected primary-expression before ')' token lines 29 -31 of main

(note previously had qstring as a header file yet changed to string since I was getting error qstring was not declared in this scope.)

View 5 Replies


ADVERTISEMENT

C++ :: Simple Class Usage Compiler Error

May 12, 2013

Full disclosure: this is an exercise from "Sams Teach Yourself C++ in 24 Hours" by Jesse Liberty and Rogers Candenhead. This refers to Chapter 9 (Hour 9 Activity 1)

I created a class called Point, in Point.h

I created a class called Rectangle in Rectangle.h and Rectangle.cpp

If I create an int main() function in Rectangle.cpp (that includes Rectangle.h), I can compile Rectangle.cpp and run the resulting program. Fine.

Question:

I create a separate file called main.cpp. I include Rectangle.h. But now the compiler complains.

Code:
$ g++ main.cpp -o main
/tmp/cc38JIph.o: In function `main':
main.cpp:(.text+0x26): undefined reference to `Rectangle::Rectangle(int, int, int, int)'
main.cpp:(.text+0x32): undefined reference to `Rectangle::getArea() const'
collect2: ld returned 1 exit status If I can create a class in Point.h and use it in Rectangle.h, why can I not just use Rectangle in main.cpp?

And the files, of course:

file: main.cpp
Code:
#include <iostream>
#include "Rectangle.h"
using std::cout;
using std::endl;

[Code] .....

View 3 Replies View Related

C# :: Inheritance Or Base Class / Polymorphism?

Sep 16, 2014

I have couple of objects which are using some amount of methods. Right now my application is not OOP and i am going to transfer it to OOP. So i would create each class for my each object. Almost all methods are in use for each object, the only one thing which is changing some of those objects passing not all parameters inside specific method. I can go two ways one is prepare interface for all methods i got and each of my classes could implement its own definition for it but other way almost all would implement exactly the same methods but with different parameters so maybe its better to create base class then for each object do inheritance from base class (polymorphism). inside base class i can prepare base methods and classes which will inherit from that class would override those methods for requirements they want.

So imagine: You got:

Memory
CPU
Latency

and all of them using mostly all of those same methods (only arguments for one of them could be use different way):

ExecuteQuery()
ExportToExcel()
PopulateDataTable()
PutValueToReport()

Now its better to do like this e.g:

Base class: Stuff
prop: name, id, date ...
methods to ovveride: ExecuteQuery(), ExportToExcel() ...

classes: CPU, Memory, Latency (inheriting from Stuff)
ovveride methods and align its definition for specific class use (remember mostly only passing args are used or not by specific class)

or go with inheritance

Interface SomeMethods
ExecuteQuery()
ExportToExcel()
PopulateDataTable()
PutValueToReport()

and each class would implemet its own definition.

The most important thing is that those every objects mostly using all of those methods and what is diffrence that one object can use all of available parameters inside this method and other one no. What i should do? Go with interface or inheritance and polymporfizm inside base class?

View 2 Replies View Related

C/C++ :: Polymorphism Is Stopping Short Of Desired Class

Mar 2, 2014

I've been working on this project which inserts data for different types of books lately, and I'm trying to utilize inheritance and polymorphism. The issue I've been having is after I create an object with my MediaFactory, I go to insert data into that type of object, but it won't reach the correct child class. The parent class in this case is MediaData. The class I'm trying to reach is Childrens, and the class that falls in between is called Book. The function I'm calling to insert the information is setData(ifstream&). This function simply places the information from a txt file into an object with the insertion operator.

Right now the program runs into the setData function of Book instead of Childrens. I need Childrens so I can enter all the required attributes (title,author,year). The call to this function is in MediaManager through the function called buildMedia, and my test is running into the case if (type == 'Y'). From there a pointer of type MediaData is created and pointed to a new object returned of type Childrens. I'm using my debugger in Xcode which does show that the correct object type (Childrens) was created.

I've tried a couple things so far. First I created another function called getData. From there I passed in *media and infile (txt input file) into that function, which then passed it right into setData with a pointer to the object and infile in the parameter. That didn't work, so I also tried going back into Childrens and removing MediaData from all my virtual functions and replacing it with Book. I got the same result when that happened; It morphed into Book class instead.

I have a portion of my UML as a reference. Childrens is a Book; Book is a MediaData. I also included all code for MediaManager, MediaHash, MediaFactory, MediaData, Book, and Childrens.

I did not include the operator overloads in the .cpp files to eliminate some redundancy.

//-----------------------------------------------------------------------------
// MediaManager.h
// Manager class for MediaData type objects
//-----------------------------------------------------------------------------

#ifndef MediaManager_H
#define MediaManager_H
#include "MediaHash.h"
#include "MediaFactory.h"
#include "MediaData.h"
using namespace std;
class MediaManager {

[Code] ....

View 3 Replies View Related

C++ :: Polymorphism On Class Instance Is Not Directly Applicable To Array

Mar 19, 2013

Below code produces run-time segmentation fault (core dumped) when execution reached line 53: delete [] array

Code 1:

#include <cstdlib>
#include <iostream>
using namespace std;
#define QUANTITY 5
class Parent {
protected:
int ID;

[Code] ....

Output of code 1:

Constructor of A: Instance created with ID=1804289383
Constructor of A: Instance created with ID=846930886
Constructor of A: Instance created with ID=1681692777
Constructor of A: Instance created with ID=1714636915
Constructor of A: Instance created with ID=1957747793
A::showID() -- ID is 1804289383
A::showID() -- ID is 846930886
A::showID() -- ID is 1681692777
A::showID() -- ID is 1714636915
A::showID() -- ID is 1957747793
Try to delete [] array..
Segmentation fault (core dumped)

Question: Why does segmentation fault happen in code 1 above?

View 9 Replies View Related

C++ ::  basic Polymorphism - Parent / Child Class Based Program

Oct 19, 2014

I am making a very basic parent/child class based program that shows polymorphism. It does not compile due to a few syntax errors reading "function call missing argument list. Lines 76 and 77, 81 and 82, and 86 and 87.

#include<iostream>
using namespace std;
class people {
public:
virtual void height(double h) = 0;
virtual void weight(double w) = 0;

[Code] ....

View 4 Replies View Related

C++ :: Variable Belonging To Base Class - Tell Compiler Consider This To Be Derived Class?

Oct 12, 2013

I have an example where I have a variable belonging to a base class, but I would like to tell the compiler that it actually belongs to a derived class. How can I do this?

// base class: R0
// derived class: R1
// see function SetR1 for the problem
class R0 {
public:
int a;

[Code] .....

View 5 Replies View Related

C++ :: Compiler Error C2664 And C2228

Nov 9, 2013

Working on a basic class program and I'm generating two compiler errors that I'm not sure how to fix. Header file, implementation cpp and main cpp are shown below. The specific errors are shown after the code.

Header file Code:

#include <iostream>
#include <string>
#include <cstdlib>
#include <iomanip>
using namespace std;

[Code].......

The file generates the second error, C2228, at lines 37-41 and 43. Basically where I tried using the second created object. Error message is "left of '.setFirstName' must have class/struct/union"

View 8 Replies View Related

C++ :: Compiler Error C2370 And C2011

Nov 29, 2013

Working on a solution involving inheritance. The whole solution is pretty massive at this point so I'll just focus on the problem areas. I'm getting a lot of "redefinition" and "undefined class type" compiler errors, including C2370, 2011, 2504, and 2027, in Benefit.h, Employee.h (the constant members are a big occurance) I'm also getting 2027 and 2079 in EmployeeMain.cpp. with my Benefit and Employee object calls.

Clearly I missed something in about how to code this correctly. Sadly the course textbook focuses on general OOP theory instead on the accompanying C++ syntax.

Benefit.h
Code:
#include <iostream>
#include <string>
#include <cstdlib>
#include <iomanip>
using namespace std;

[Code] .....

View 4 Replies View Related

C++ :: Unexpected Expression Compiler Error

Jul 30, 2013

My compiler (GCC) keeps expecting an expression where it shouldn't in 1 specific piece of my code:

int zxcNewWindow( HWND parent, TCHAR *text, zxWINDOW *kid,
UINT style, int x, int y, int w, int h, int type )
// right here
{
*kid = zxDefWINDOW;

The project contains only 2 files right now and the settings are just the default for an empty Code::Blocks 12.11 project. Both files are in UTF-8 format (tried in ASCII too), I just cannot see why this is not compiling correctly. I'll post the files in the next two posts.

Edit: For those of you who didn't get what the error was from the above here's the full log:

mingw32-gcc.exe -Wall -g -DzxDEBUG -c C:MePrjscppzxGUImain.c -o objmain.o
C:MePrjscppzxGUImain.c: In function 'zxcNewWindow':
C:MePrjscppzxGUImain.c:39:10: error: expected expression before '{' token
Process terminated with status 1 (0 minutes, 0 seconds)
1 errors, 0 warnings (0 minutes, 0 seconds)

View 8 Replies View Related

C++ :: Compiler Error - Expression Must Have A Constant Value

May 20, 2014

I am trying to run this source code but i am getting the compiler error Expression Must Have a Constant Value. I tried making both the variables x and y constants and assigned them to a significantly big number but then i am getting the error expression must be a modifiable lvalue.I have made comments in the code in front where Visual Studio is giving me the syntax error (red squiggly line).

#include<iostream>
#include <string>
#include<cmath>
using namespace std;
int main(){
int x;
int y;

[Code] ......

View 3 Replies View Related

C/C++ :: Compiler Error / Left Operand Must Be L-value

Oct 15, 2014

I am having problems compiling this program. line 29 causes the error "left operand must be l-value".

// chap5proj.cpp : Defines the entry point for the console application.
//
# include <stdafx.h>
# include <iostream>
using namespace std;
int main() {
double mph, time, disPerHour, milesTrav;

[code]....

View 2 Replies View Related

C/C++ :: Difference Between Compiler Error And Warning?

Jun 8, 2013

in c program what is the difference between a compiler error and a warning

View 1 Replies View Related

C++ :: Compiler Error C2374 - Multiple Initialization

Nov 1, 2013

Well, I thought I had this program working but now I'm getting the above referenced compiler error. The program is just a basic user interface. It is for a classwork assignment.

The program is to accept user information as a string, convert it (if needed) to either the int or double variable, and then display the result. I'm using stringstream convert to make the change between types, but I'm not sure if I'm using it right (that might be what's causing the error, I'm not sure). Line 36-37 generates the error.

Code:
#include <iostream>
#include <iomanip>
#include <sstream>
using namespace std;

[Code] ....

View 5 Replies View Related

C++ :: Header File - Compiler Error Before Directory

May 18, 2014

I'm trying to compile this code which is a header file.

#ifndef CUBEMAP_H_INCLUDED
#define CUBEMAP_H_INCLUDED
#include "Texture.h"
#include <string>
class CubeMap : Texture {

[Code] ....

But I get the following error:

|9|error: expected ')' before 'Directory'|

How can i resolve this?

View 6 Replies View Related

C/C++ :: Reversing String Loop - Compiler Error

Feb 13, 2014

I need to reverse this loop. get how to do it in order but when i have to reverse it i get a compiler error

int main() {
cout << "Enter 3 cities" << endl;
string cities;
for ( int i = 0; i < 3; ++i ) {
getline(cin, cities[3];

[Code] ....

View 2 Replies View Related

C/C++ :: GCC Compiler Does Not Detect Multiple Definition Error

Oct 31, 2012

I am trying to compile the files file1.c and file2.c using Mingw (gcc)

/////////////////////
header.h
////////////////////
#ifndef header
#define header  
int variable;  
#endif

[Code] ....

I would have expected a multiple defnition error when linking the two .c files. as in both the files, with the 'int variable' command, the variable 'variable' is defined (memory allocated) and during linking the linker doesnot know which variable to link to.

I get an error though when i use "int variable =123;" in the header file instead of the "int variable;" statement. i dont understand as in both the cases the variable is defined (memory is allocated) and the linker should give a multiple definition error.

View 8 Replies View Related

C++ :: A Compiler Error With The Implementation Of Smart Pointer

Oct 8, 2014

Here is my code,

Code:
class A {
public:
void display() {
cout<<"A"<<endl;

[Code] .....

The compiler error is "error C2039: 'display' : is not a member of 'SP<T>'". What am I missing here?

View 14 Replies View Related

Visual C++ :: Compiler Error With Cout Object

Dec 15, 2012

I am asp.net C# developer. I decided to tackle C++, so I started today. This is probably something simple I am sure.

Code:
srand(static_cast<unsigned int>(time(0)));
int choice = rand() % NUM_WORDS;
string theWord = WORDS[choice][WORD];
string theHint = WORDS[choice][HINT];

[Code] ....

The error is happening on the last output operator, just before the jumble variable on the last line.The error is:

Code:
Intellisense: no operator"<<" matches these operands

operand types are: std::basic_ostream<char, std::char_traits<char> <<std::string

I understand what its saying, but jumble is a std::string

Here are my preprocessor directives and using statements

Code:
#include "stdafx.h"
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;

View 4 Replies View Related

C++ :: Implementing Hash Table - STL List Compiler Error

Jun 5, 2013

I have been implementing a Hash Table class made, and ran into a bit of a problem in my Delete function. I have the hash table made up as

vector<list<HashNode<T,X>>> m_Table

My problem is when I iterate through the vector, and then the list in that current element to try and find the Node I want to delete, the STL list class gives me the error:

Error1error C2678: binary '==' : no operator found which takes a left-hand operand of type 'HashNode<T,X>' (or there is no acceptable conversion)

Here's the Delete function:

template <typename T, typename X>
void HashTable<T,X>::Delete(T key) {
HashNode<T,X> Node;
HashNode<T,X> NodeTemp;
list<HashNode<T,X>> temp;
list<HashNode<T,X>>::iterator it;
vector<list<HashNode<T,X>>>::iterator iter;

[Code] ....

Why it's not letting me do the .Remove() function?

View 3 Replies View Related

C++ :: Class Not Seen By Compiler?

Sep 18, 2014

I have an issue. VS 2013 isn't recognizing objects that I've declared when I use class functions.I'm getting this error: "Line 14 and 15: Error C2228: left of '.asciiToFpc6' must have class/struct/union"...Here's the relevant code:

Source.cpp

#include <cstdlib>
#include <iostream>
#include <fstream>
#include <string>
#include "fpc6.h"

[code].....

Additionally VS apparently doesn't like my bitwise operators in my class functions and doesn't think they're doing anything. It gives "warning C4552: ['|', '<<', '>>', '&'] : operator has no effect; expected operator with side-effect" for all of them, but it seems to me the code should work fine and actually accomplish things....

View 9 Replies View Related

C/C++ :: Error Thrown By Compiler / Identifier Expected And Declaration Terminated Incorrectly

Jan 30, 2015

Error message is identifier expected and declaration terminated incorrectly.

//to define a class Employee
#include<iostream.h>
#include<stdio.h>
#include<string.h>
#include<conio.h>
class cEmp {

[code]....

View 7 Replies View Related

C++ :: Compiler Will Not Allow To Call A Public Method In Another Class

Feb 23, 2013

I have read the book over and over and I thought I understand "CLASS". But when I applied it and write the code the compiler tells me that there is a compiling error.

1. I have this method addProduct(Product* pProduct) in a Class called ProductRack, the code is in ProductRack.cpp file. The declaration of the Class methods and private variables are in ProductRack.h header file.

2. But when I call a method in the DeliveryCHute Class from the ProductRack Class I get a compiler errors which are these:

A.IntelliSense: a nonstatic member reference must be relative to a specific object
B.error C2352: 'Project1::DeliveryChute::insertProduct' : illegal call of non-static member function

And this is causing the error:

if (Project1::DeliveryChute::insertProduct(pProduct) == false)

//THIS IS JUST ONE METHOD INSIDE ProductRack.cpp
bool
Project1::ProductRack::addProduct(Product* pProduct) {
// Todo : Implementing
if (Project1::DeliveryChute::insertProduct(pProduct) == false)
return true;

[Code] .....

View 5 Replies View Related

C++ :: Compiler And Linker Errors For Linked List Class And Application

Aug 31, 2014

I am trying to write a program that will take a list of integers from a file and write them to another text file. I've been banging my head at this for days trying to get it to compile as it is riddled with linker and compiler errors.

**************************header*************************

#ifndef LINKEDLIST_H
#define LINKEDLIST_H
#include <iostream>
using namespace std;
template <class T>
class linkedList {

[Code] ....

View 6 Replies View Related

C++ :: Why It Is Runtime Polymorphism

Apr 4, 2013

class Base
{
.....
.....
.....
virtual void display();

[code]....

in the above polymorphism why is it called runtime polymorphism when i can say seeing the code itself that display() function in derived gets executed with ptr->display(),so how does it become runtime polymorphism when i could get decide at compile itself ???

View 6 Replies View Related

Visual C++ :: Reach Top Class Inherits From Goal Class - Linker Error

Dec 10, 2012

Linker error.

First off the error

Code:
Error1error LNK2019: unresolved external symbol "public: __thiscall ReachTop<class Character>::ReachTop<class Character>(class Character *)" (??0?$ReachTop@VCharacter@@@@QAE@PAVCharacter@@@Z) referenced in function "void __cdecl `dynamic initializer for 'gReachTop''(void)" (??__EgReachTop@@YAXXZ)Main.objDecisionTest

Reach Top class inherits from Goal Class

Goal Class

Code:
#ifndef _GOAL_H
#define _GOAL_H
#include "Action.h"
#include <list>
template <class T>
class Goal

[Code] ....

Code to create

Code:
Character* gCharacter = new Character(1, gWorld);
Goal<Character>* gReachTop = new ReachTop<Character>(gCharacter);

I can provide the character class and its inheritance aswell if you like.

View 4 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved