2013-05-06 72 views
0

在功能main':
[Linker error] undefined reference to
Binary_to_Decimal()“
[连接子错误]未定义参考`Decimal_to_Binary()”
上十进制工作到二进制和二进制到十进制的程序。 不幸的是我碰到了编译错误,我缺乏修复的知识。 我将非常感谢帮助解决和了解问题。
这是程序的源代码。如何解决链接器错误?

#include <iostream> 
#include <string> 
#include <bitset> 
void Binary_to_Decimal(); 
void Decimal_to_Binary(); 


int main (int argv, char argc) { 
     while(1<2){ 
     int m_Choice; 
     std::cout << "Enter 1 - for Binary to Decimal" << std::endl; 
     std::cout << "Enter 2 - for Decimal to Binary" << std::endl; 
     std::cin >> m_Choice; 
     if (m_Choice == 1) { 
        Binary_to_Decimal(); 
        }else if (m_Choice == 2) { 
         Decimal_to_Binary(); 
         } 



    return 0; 
    } 
}  
void Binary_To_Decimal(){ 
    std::string Binary_to_Decimal_cstr; 
    std::cout << "Please enter binary number: " << std::endl; 
    std::cin>>Binary_to_Decimal_cstr; 
    std::cout<<Binary_to_Decimal_cstr; 
    std::cout <<"converted to Decimal is:" << std::bitset<32>(Binary_to_Decimal_cstr).to_ulong(); 
    std::cout << std::endl; 
    } 

void Decimal_To_Binary(){ 


     int Decimal_to_Binary_Var; 
     std::cout << "Please enter Decimal number: " << std::endl; 
     std::cin >> Decimal_to_Binary_Var; 
     std::cout << Decimal_to_Binary_Var; 
     std::cout << "converted to Binary is: " << std::bitset<32>(Decimal_to_Binary_Var); 
     std::cout << std::endl; 
     } 
+5

函数名称是**区分大小写**。 – Mat 2013-05-06 07:50:00

+0

尝试'while(m_Choice!= 0)',然后当您完成测试时按0退出,从一些时髦的习惯中拯救自己。 – ChiefTwoPencils 2013-05-06 08:00:55

回答

1

区分大小写的问题!

void Binary_to_Decimal(); --> void Binary_To_Decimal(); 
      ^       ^


void Decimal_to_Binary(); --> void Decimal_To_Binary(); 
      ^       ^

void Binary_to_Decimal()编译器搜索,但你implelemted void Binary_To_Decimal();这是不同的东西。

1

您可以拨打电话Binary_to_Decimal,但该功能被称为Binary_To_Decimal。请注意0​​部分中的小写字母和大写字母。与其他功能相同的东西。

基于C语言的所有语言(如C++)都区分大小写。

1

你给函数Decimal_To_BinaryBinary_To_Decimal命名,但是你用小写的“t”来调用它们,因此编译器不知道你正在调用哪些函数。

名称必须完全匹配,并且区分大小写。

0

您调用的函数是“Binary_to_Decimal”,但在“Decimal_To_Binary()”{名称不完全相同}中实现的函数...与“Decimal_to_Binary”大小写相同。

+0

谢谢大家的回复。你一直很好的帮助:) – Apologizingnoob 2013-05-06 09:39:46

相关问题