| | |
C++ Questions
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
I am trying to write a program to convert a roman numeral to decimal. If I define a variable with:
Also, I am getting an error when I try to compile my implementation file (my header file compiles fine). I can't locate my mistake...
Here are my compiler errors:
romanTypeImp.cpp: In function `int main()':
romanTypeImp.cpp:15: error: `romanToDecimal' undeclared (first use this function)
romanTypeImp.cpp:15: error: (Each undeclared identifier is reported only once for each function it appears in.)
I am using cygwin on XP and gcc (compiling with g++):
gcc version 3.4.4 (cygming special) (gdc 0.12, using dmd 0.125)
Here is my header file:
Here is my implementation file:
char roman_num[15]; can I then select individual characters in that roman numeral with: roman=roman_num[i]; where "i" is a number value of the character I want to retrieve from 0-14?Also, I am getting an error when I try to compile my implementation file (my header file compiles fine). I can't locate my mistake...
Here are my compiler errors:
romanTypeImp.cpp: In function `int main()':
romanTypeImp.cpp:15: error: `romanToDecimal' undeclared (first use this function)
romanTypeImp.cpp:15: error: (Each undeclared identifier is reported only once for each function it appears in.)
I am using cygwin on XP and gcc (compiling with g++):
gcc version 3.4.4 (cygming special) (gdc 0.12, using dmd 0.125)
Here is my header file:
C++ Syntax (Toggle Plain Text)
class romanType { public: romanType(); // Default constructor void romanToDecimal(char roman); // Convert from roman numeral to decimal void printRoman(); // Print roman numeral void printDecimal(); // Print decimal value private: char roman; // Store a single roman numeral int decimal; // Store decimal value char roman_num[15]; // Store roman numeral array of 15 characters int numberM; // Store value of roman numeral M int numberD; // Store value of roman numeral D int numberC; // Store value of roman numeral C int numberL; // Store value of roman numeral L int numberX; // Store value of roman numeral X int numberV; // Store value of roman numeral V int numberI; // Store value of roman numeral I };
Here is my implementation file:
C++ Syntax (Toggle Plain Text)
#include <iostream> #include "romanType.h" using namespace std; char roman; void romanType::romanToDecimal(char roman) { cout<<"Testing"<<roman; } int main() { cout<<endl<<"Enter a Roman Numeral: "; romanToDecimal('M'); }
Thanks,
MrLew
MrLew
romanToDecimal is a member function lacking an object.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
I'm not grasping what you mean by an object... I tried looking it up, but I don't think I found the right solution. I made the two changes below, but still get the following error when I compile:
undefined reference to `romanType::romanType()'
undefined reference to `romanType::romanType()'
C++ Syntax (Toggle Plain Text)
#include <iostream> #include "romanType.h" using namespace std; char roman; romanType myroman; //Change #1 void romanType::romanToDecimal(char roman) { cout<<"Testing"<<roman; } int main() { cout<<endl<<"Enter a Roman Numeral: "; myRoman. romanToDecimal('M'); //Change #2 }
Thanks,
MrLew
MrLew
You tell the compiler that you'll write a function: Then you don't provide one. The compiler feels left out.
Note also that the language is case-sensitive, so myroman is not the same as myRoman.
class romanType
{
public:
romanType();Note also that the language is case-sensitive, so myroman is not the same as myRoman.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Thanks for the pointers... I fixed the additional problems based off of your last tip. I've got a new error now...
romanTypeImp.cpp:22: error: return type specification for constructor invalid
Header file:
Implementation file:
romanTypeImp.cpp:22: error: return type specification for constructor invalid
Header file:
C++ Syntax (Toggle Plain Text)
class romanType { public: romanType(); // Default constructor void romanToDecimal(char roman); // Convert from roman numeral to decimal void printRoman(); // Print roman numeral void printDecimal(); // Print decimal value private: char roman; // Store a single roman numeral int decimal; // Store decimal value char roman_num[15]; // Store roman numeral array of 15 characters int numberM; // Store value of roman numeral M int numberD; // Store value of roman numeral D int numberC; // Store value of roman numeral C int numberL; // Store value of roman numeral L int numberX; // Store value of roman numeral X int numberV; // Store value of roman numeral V int numberI; // Store value of roman numeral I };
Implementation file:
C++ Syntax (Toggle Plain Text)
#include <iostream> #include "romanType.h" using namespace std; void romanType::romanToDecimal(char roman) { cout<<"Testing"<<roman; } void romanType::printRoman() { cout<<"Testing 2"; } void romanType::printDecimal() { cout<<"Testing 3"; } void romanType::romanType() { printDecimal(); } int main() { romanType myRoman; cout<<endl<<"Enter a Roman Numeral: "; myRoman.romanToDecimal('M'); }
Thanks,
MrLew
MrLew
void romanType::romanType() "One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
![]() |
Similar Threads
- I have a few questions to be patched up can anybody get these to me ? (C++)
- Questions about Forum (Geeks' Lounge)
- Preparing for an interview and need some questions answered (C)
- Wireless Questions (Networking Hardware Configuration)
- Linux printing questions (*nix Hardware Configuration)
- Tutorials & Code Submissions - Questions? (DaniWeb Community Feedback)
Other Threads in the C++ Forum
- Previous Thread: Console Color
- Next Thread: Quick question about switch()
Views: 2455 | Replies: 5
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays assignment beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete developer display dll email encryption error file format forms fstream function functions game generator getline givemetehcodez graph iamthwee ifstream image input int java lib loop looping loops map math matrix memory multidimensional multiple newbie news node number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg search sort sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






