I am trying to write a program to convert a roman numeral to decimal. If I define a variable with: 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:

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:

#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');
}

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()'

#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
}

You tell the compiler that you'll write a function:

class romanType
{
public:
 romanType();

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.

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:

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:

#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');
}
This article has been dead for over six months. Start a new discussion instead.