이 프로그램을 Turbo C++로 작성할 때 잘 동작합니다. 그러나 CodeBlocks, Xcode에 쓸 때 char
과 관련된 오류가 발생하며 그 이유를 알 수 없습니다. 문자열로 사용할 char* name
같은 것을 선언 할 수 있다고 생각했습니다.포인터로 함수를 전달하는 포인터
이 프로그램은 다중 레벨 상속에 관한 것입니다.
전환에서 : 기능에 금리 및 기간을 전달,이 함수를 호출, 내가 갖는이 통지의 장소에서
#include <string> #include <iostream> #include <fstream> using namespace std; class banktype1{ public: char *accountType; float interestAmt,depositAmt,period,totalAmt; public: void interestCal(char *x,int y,int z){ accountType=&x; depositAmt=y; period=z; if(accountType=="A") interestAmt=depositAmt*0.5*period; else if(accountType=="B") interestAmt=depositAmt*0.15*period; else if(accountType=="C") interestAmt=depositAmt*0.25*period; } }; class banktype2:public banktype1{ public: void displayData(){ cout<<interestAmt<<"\n"<<depositAmt<<endl; cout<<"Total"<<interestAmt+depositAmt; } }; class banktype3:public banktype2{ }; int main(){ banktype3 b1; b1.interestCal("A",1000,12); b1.interestCal("B",1000,12); b1.interestCal("C",1000,12); b1.displayData(); return 0; }
type.` 계정에 따라 출력을 표시합니다 char *에 대한 문자열 리터럴은 더 이상 사용되지 않습니다.
도 내가 갖는 조건 경우의 장소에서
: 리터럴 문자열에 대한 비교결과는 지정되지 않습니다 (대신 사용 strncmp)
이 코드에는 오류가 * 많이 * 있습니다. 당신이 질문을하지 않았으므로 당신을 도울 수 없습니다. 이러한 오류 메시지의 의미를 이해합니까? 그렇다면 무엇이 그들을 고치지 못하게합니까? 그렇지 않다면, 당신은 그렇게 말해야합니다 - 그렇지 않으면 우리는 당신에게 필요한 도움이 무엇인지 모릅니다. –
Turbo C++는 구식입니다. 마지막 발표는 2006 년입니다. 강사가 2014 년에 C++을 가르치기 위해 그것을 왜 사용하는지는 나에게는 설명 할 수 없습니다. –
@DavidSchwartz 안녕하세요. 함수 매개 변수를 전달하는 char 및 pincers 사용에 대한 명확하지 않은 이미지가 있습니다. 몇 가지 대답을 읽은 후에. 예 : 'const'를 삭제 한 후 * if compare를 할당하면 효과가 발생합니다. –