在c++中找不到头函数
Header functions not found in C++
我一直在尝试用SFML制作一个简单的图形计算器(尽管这个问题与SFML无关)。所以我做了一个库,可以把字符串方程变成双答案。但是,当我试图添加说库(StringDouble.h和StringDouble.cpp)到main.cpp,我得到:
D:SFML projectsCalculatormain.cpp||In function 'double calculateString(std::string)':|
D:SFML projectsCalculatormain.cpp|30|error: 'Mult' was not declared in this scope|
D:SFML projectsCalculatormain.cpp|31|error: 'Div' was not declared in this scope|
D:SFML projectsCalculatormain.cpp|35|error: 'Addify' was not declared in this scope|
D:SFML projectsCalculatormain.cpp|36|error: 'Sub' was not declared in this scope|
D:SFML projectsCalculatormain.cpp|38|error: 'S2D' was not declared in this scope|
D:SFML projectsCalculatormain.cpp||In function 'int main()':|
D:SFML projectsCalculatormain.cpp|88|error: 'D2S' was not declared in this scope|
D:SFML projectsCalculatormain.cpp||In function 'double calculateString(std::string)':|
D:SFML projectsCalculatormain.cpp|39|warning: control reaches end of non-void function [-Wreturn-type]|
||=== Build finished: 6 errors, 1 warnings (0 minutes, 0 seconds) ===|
这很奇怪,因为我有另一个链接头文件Button.h和Button.cpp。这很可能是一个愚蠢的错误,但我盯着代码看了几个小时,什么也没发现:
main.cpp
#include "SFML/Graphics.hpp"
#include "Button.h"
#include <iostream>
#include <sstream>
#include "StringDouble.h"
using namespace std;
double calculateString(string currStr)
{
for (unsigned int i=0;i<currStr.size();i++)
{
if (currStr[i]=='*') currStr=Mult(currStr, i);
if (currStr[i]=='/') currStr=Div(currStr, i);
}
for (unsigned int i=0;i<currStr.size();i++)
{
if (currStr[i]=='+') currStr=Addify(currStr, i);
if (currStr[i]=='/') currStr=Sub(currStr, i);
}
return S2D(currStr);
}
int main()
{
bool running=1;
sf::Event event;
sf::RenderWindow window(sf::VideoMode(212, 284), "Calculator");
sf::Font font;
// ((sf::Image&)font->GetImage(30U)).SetSmooth(false);
sf::Color CharColor(160, 160, 160, 255);
double curnum=0;
if (!font.loadFromFile("trebuc.ttf")) cout<<"Your font is shitting itself"<<endl;
window.setFramerateLimit(30);
NumButton nums[10];
Button curnumbut(12, 30, 190, 50);
curnumbut.setColors(sf::Color(230, 239, 251), sf::Color::Black, sf::Color::Black);
curnumbut.setText("0", font, 16, sf::Color::Black);
pmtdButton pmtd[7];
pmtd[0].initialize('+', font, sf::FloatRect(126, 246, 32, 26));
pmtd[1].initialize('-', font, sf::FloatRect(126, 214, 32, 26));
pmtd[2].initialize('*', font, sf::FloatRect(126, 182, 32, 26));
pmtd[3].initialize('/', font, sf::FloatRect(126, 150, 32, 26));
pmtd[4].initialize('%', font, sf::FloatRect(162, 150, 32, 26));
pmtd[5].initialize('.', font, sf::FloatRect(88, 246, 32, 26));
for (int i=0;i<10;i++)
nums[i].initialize(i, font);
while (running)
{
while (window.pollEvent(event))
if (event.type==sf::Event::Closed) running=0;
// test.checkMouse(sf::Mouse::getPosition(window));
// test.updateColor();
for (int i=0;i<10;i++)
{
if (nums[i].checkMouse(sf::Mouse::getPosition(window))) addnum(curnum, nums[i]);
nums[i].updateColor();
}
for (int i=0;i<6;i++)
{
if (pmtd[i].checkMouse(sf::Mouse::getPosition(window))) {}
pmtd[i].updateColor();
}
curnumbut.setText(D2S(curnum), font, 16, sf::Color::Black);
window.clear();
for (int i=0;i<10;i++)
window.draw(nums[i]);
for (int i=0;i<6;i++)
window.draw(pmtd[i]);
window.draw(curnumbut);
window.display();
// cout<<curnum<<endl;
}
window.close();
return 0;
}
StringDouble.h
#ifndef ADD_H
#define ADD_H
struct doubleReturn
{
double x, y;
};
double S2D (std::string a);
std::string D2S (double number);
doubleReturn GetPrevDouble(std::string x, int pos)
doubleReturn GetNextDouble(std::string x, int pos)
std::string Addify(std::string x, int pos);
std::string Sub(std::string x, int pos);
std::string Mult(std::string x, int pos);
std::string Div(std::string x, int pos);
#endif
StringDouble.cpp
#include <sstream>
#include <iostream>
#include "StringDouble.h"
//using namespace std;
double S2D (std::string a)
{
return atof(Temperature.c_str());
}
std::string D2S (double number)
{
ostringstream buff;
buff<<std::fixed<<number;
std::string x=buff.str();
while(x[x.size()-1]=='0')
x.erase(x.size()-1);
if (x[x.size()-1]=='.') x.erase(x.size()-1);
return x;
}
doubleReturn GetPrevDouble(std::string x, int pos)
{
int i;
bool flag=0;
for(i=pos;i>=0;i--)
if (x[i]<'0'||x[i]>'9') {if (x[i]=='.'&&flag==0) flag=1;
else break;}
doubleReturn ret.x=S2D(x.substr(i+1, pos-1));
ret.y=i+1;
}
doubleReturn GetNextDouble(std::string x, int pos)
{
int i;
bool flag=0;
for(i=pos;i<x.size();i++)
if (x[i]<'0'||x[i]>'9') {if (x[i]=='.'&&flag==0) flag=1;
else break;}
DoubleReturn ret;
ret.x=S2D(x.substr(pos+1, i-1));
ret.y=i-1;
return ret;
}
std::string Addify (std::string x, int pos)
{
doubleReturn ret1=GetPrevDouble(x, pos);
doubleReturn ret2=GetNextDouble(x, pos));
return x.substr(0, ret1.y)+D2S(ret1+ret2)+x.substr(ret2.y, x.end());
}
std::string Sub (std::string x, int pos)
{
doubleReturn ret1=GetPrevDouble(x, pos);
doubleReturn ret2=GetNextDouble(x, pos));
return x.substr(0, ret1.y)+D2S(ret1-ret2)+x.substr(ret2.y, x.end());
}
std::string Mult (std::string x, int pos)
{
doubleReturn ret1=GetPrevDouble(x, pos);
doubleReturn ret2=GetNextDouble(x, pos));
return x.substr(0, ret1.y)+D2S(ret1*ret2)+x.substr(ret2.y, x.end());
}
std::string Div (std::string x, int pos)
{
doubleReturn ret1=GetPrevDouble(x, pos);
doubleReturn ret2=GetNextDouble(x, pos));
return x.substr(0, ret1.y)+D2S(ret1/ret2)+x.substr(ret2.y, x.end());
}
欢迎任何帮助我指出我最可能犯的愚蠢错误。:)
你所说的"愚蠢的错误"在:
后面缺少分号doubleReturn GetPrevDouble(std::string x, int pos)
doubleReturn GetNextDouble(std::string x, int pos)
您还需要#include <string>
相关文章:
- 编译器找不到'aligned_alloc'函数
- 在 c++ 中找不到此函数的标识符
- LLVM 选择找不到函数传递
- 找不到 #define 的函数定义
- LD 找不到生成的函数
- C++线程找不到函数作为参数(链接器)
- 为什么 std::sort 找不到合适的(静态成员)函数重载?
- Javascript 找不到使用 emscripten 编译的导出 WASM 函数
- 给定一个 3 x 3 矩阵或任何 n x n 矩阵,为什么我的以下函数找不到对角线差异?
- QObject::连接不起作用 - 使用函数语法找不到信号
- VS 2017 C++编译器在 VS 2005 中找不到匹配函数
- 找不到如何创建使用指针、字符和 for 函数组合的程序
- 这个基于范围的'for'语句需要一个合适的函数,但找不到任何函数
- im调用函数时找不到标识符?
- 找不到使用 bitset 实例化模板函数的有效方法
- 如何修复找不到匹配的重载函数?
- ADL 找不到重载函数
- 构造函数找不到合适的定义,以及 100 个其他错误?
- 类函数找不到类定义的变量
- 平均函数找不到正确的平均c++