| | |
simple code not working
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jun 2009
Posts: 8
Reputation:
Solved Threads: 0
•
•
•
•
Please find the details of the code in attachment.
I am new c++ student. Please let me know the fault.
Regards,
Shivi
g++ -c brick.cc
g++ -o my.out:shape.o brick.o Exo.o
brick.o: In function `Brick::Volume() const':
brick.cc:(.text+0x1db): undefined reference to `Rectangle::getLength() const'
brick.cc:(.text+0x1e9): undefined reference to `Rectangle::getWidth() const'
brick.o: In function `Brick::Display()':
brick.cc:(.text+0x21e): undefined reference to `Rectangle::getLength() const'
brick.cc:(.text+0x24f): undefined reference to `Rectangle::getWidth() const'
brick.cc:(.text+0x280): undefined reference to `Rectangle::Area() const'
brick.o: In function `Brick::setDimensions(double, double, double)':
brick.cc:(.text+0x388): undefined reference to `Rectangle::setLength(double)'
brick.cc:(.text+0x39a): undefined reference to `Rectangle::setWidth(double)'
collect2: ld returned 1 exit status
make: *** [my.out] Error 1
Last edited by Ancient Dragon; Jul 3rd, 2009 at 5:44 pm. Reason: dsable smilies in text
•
•
Join Date: Jun 2009
Posts: 8
Reputation:
Solved Threads: 0
•
•
•
•
post the header file that defines Rectangle class and the code brick.cc
C++ Syntax (Toggle Plain Text)
#ifndef BRICK_H_ #define BRICK_H_ #include "shape.h" class Brick { public: Brick() {}; void setThickness(double Tck); void setDimensions(double l, double w, double t); void setColor(char* clr); void setTexture(char* txr); char* getColor() const; char* getTexture() const; double Volume() const; void Display(); private: Rectangle shape; char* Color; char* Texture; double Thickness; }; #endif // BRICK_H_
C++ Syntax (Toggle Plain Text)
#include <iostream> #include "brick.h" using namespace std; void Brick::setThickness(double Tck) { Thickness = Tck; } void Brick::setColor(char* clr) { Color = clr; } void Brick::setTexture(char* txr) { Texture = txr; } void Brick::setDimensions(double l, double w, double t) { shape.setLength(l); shape.setWidth(w); setThickness(t); } char* Brick::getColor() const { return Color; } char* Brick::getTexture() const { return Texture; } double Brick::Volume() const { return shape.getLength() * shape.getWidth() * Thickness; } void Brick::Display() { cout << "\nBrick characteristics"; cout << "\n\tLength = " << shape.getLength(); cout << "\n\tWidth = " << shape.getWidth(); cout << "\n\tArea = " << shape.Area(); cout << "\n\tVolume = " << Volume(); cout << "\n\tColor = " << getColor(); cout << "\n\tTextture = " << getTexture(); cout << endl; }
shape.h
C++ Syntax (Toggle Plain Text)
#ifndef _SHAPE_H #define _SHAPE_H class Rectangle { public: Rectangle(double l = 0, double w = 0) : Length(l), Width(w) {} void setLength(double lgt); void setWidth(double wdt); double getLength() const; double getWidth() const; double Perimeter() const; double Area() const; void Properties(); private: double Length; double Width; }; #endif // _SHAPE_H
shape.cc
C++ Syntax (Toggle Plain Text)
#include <iostream> #include "shape.h" using namespace std; void Rectangle::setLength(double lgt) { Length = lgt; } void Rectangle::setWidth(double wdt) { Width = wdt; } double Rectangle::getLength() const { return Length; } double Rectangle::getWidth() const { return Width; } double Rectangle::Perimeter() const { return 2 * (Length + Width); } double Rectangle::Area() const { return Length * Width; } void Rectangle::Properties() { cout << "\nRectangle characteristics"; cout << "\n\tLength = " << Length; cout << "\n\tWidth = " << Width; cout << "\n\tPerimeter = " << Perimeter(); cout << "\n\tArea = " << Area() << endl; }
my.make
C++ Syntax (Toggle Plain Text)
my.out:shape.o brick.o Exo.o g++ -o my.out:shape.o brick.o Exo.o Exo.o: Exo.cc brick.h shape.h g++ -c Exo.cc shape.o: shape.cc shape.h g++ -c shape.cc brick.o: brick.cc brick.h g++ -c brick.cc clean: rm *.o my.out
Last edited by Ancient Dragon; Jul 5th, 2009 at 10:00 am. Reason: add code tags and disable smilies
![]() |
Similar Threads
- Assembly Code not working on Vista but worked on XP (Assembly)
- my code is working but for some reason i cant restart my loop (C++)
- CHECKBOX VAILDATION CODE not working (PHP)
- Does this code working after changing environment? (VB.NET)
- javascript code not working in firefox (JavaScript / DHTML / AJAX)
- Uploading File Not Working...simple code, what's wrong? (PHP)
- simple code (C++)
- CAn anyone provide me a very simple code for shopping cart? (PHP)
- I would liike to multiply two matrices but my code is not working..help me out! (C++)
Other Threads in the C++ Forum
- Previous Thread: pyramid building help!
- Next Thread: Help with a vector<vector<string> *>
| Thread Tools | Search this Thread |
api array based binary c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock wordfrequency wxwidgets






