定义了一个类与方法,就是编译不过去,新手,求指导

十年的老股民 2019-08-19 07:36:54
我定义了一个类与方法,就是编译不过去,新手,求指导
实现功能 B.cpp调用A.cpp的方法 并且打印temp_c

//temp.h
#pragma once
#include <iostream>
#ifndef _TEMP_H_
#define _TEMP_H_
class temp
{
public:
temp();
~temp();
void str_way(std::string &str);
private:
};
temp::temp()
{}
temp::~temp()
{}
#endif // !_TEMP_H_


//temp.cpp
#include <string>
#include <iostream>
#include "stdafx.h"
#include "temp.h"
#include <string>
void temp::str_way(std::string &str) {
extern std::string a;
int temp_a = 1;
int temp_b = 2;
int temp_c = 0;
temp_c = temp_a + temp_c;
std::cout << temp_c << std::endl;
a = str;
std::cout << a << std::endl;
std::cout << std::endl;
}


//A.cpp
#include "stdafx.h"
#include "temp.h"
#include <string>
#include <iostream>
using namespace std;
int main()
{
string str_new = "1";
temp temp_new;
temp_new.str_way(str_new);

return 0;
}


图中ConsoleApplication1.cpp为A.cpp


编译报错
...全文
139 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
十年的老股民 2019-08-19
  • 打赏
  • 举报
回复
问题解决:
由于创建了构造,析构函数,需要在cpp里构建构造析构函数即可
十年的老股民 2019-08-19
  • 打赏
  • 举报
回复

楼上的,不对呀
尐东东 2019-08-19
  • 打赏
  • 举报
回复

//temp.h
#pragma once
#include <iostream>
#ifndef _TEMP_H_
#define _TEMP_H_
class temp
{
public:
    temp(){}
    ~temp(){}
    void str_way(std::string &str);
private:
};
#endif // !_TEMP_H_

#include <string>
#include <iostream>
#include "stdafx.h"
#include "temp.h"
#include <string> 
void temp::str_way(std::string  &str) {
    std::string a;  //remove extern
    int temp_a = 1;
    int temp_b = 2;
    int temp_c = 0;
    temp_c = temp_a + temp_c;
    std::cout << temp_c << std::endl;
    a = str;
    std::cout << a << std::endl;
    std::cout << std::endl;
}
内容概要:本文档介绍了一种基于Simulink的永磁同步电机(PMSM)转速控制仿真模型,重点实现了“超螺旋滑模控制器”与“有限时间扩张状态观测器(FTESO)”相结合的先进控制策略。该方法通过FTESO在有限时间内快速收敛并实时估计系统内部动态与外部扰动,结合超螺旋滑模控制实现无颤振的高精度转速跟踪,有效提升了电机在复杂工况下的动态响应性能与抗干扰能力。同时,系统支持转动惯量等关键参数的在线辨识,增强了控制系统的自适应性与鲁棒性。作为“顶刊复现”系列科研资料之一,本资源聚焦于现代非线性控制理论在电机驱动系统中的仿真验证与工程应用。; 适合人群:自动化、电气工程、控制科学与工程等相关专业的研究生、科研人员及具备一定MATLAB/Simulink基础的高年级本科生。; 使用场景及目标:① 深入学习和掌握滑模控制、扩张状态观测器(ESO)、自抗扰控制(ADRC)等现代非线性控制理论在永磁同步电机系统中的具体实现方法;② 复现高水平学术论文中的先进控制算法,提升科研仿真能力与理论转化实践的能力;③ 为高性能电机控制、扰动抑制、参数在线辨识等关键技术研究提供可靠的仿真平台与技术参考。; 阅读建议:建议读者首先研读相关控制理论的学术文献,深入理解超螺旋滑模与有限时间ESO的设计原理与数学基础,再结合Simulink模型逐模块分析其搭建逻辑与参数整定方法,重点关注扰动观测与前馈补偿的实现机制,并可通过设置不同负载扰动、参数突变等工况测试系统的鲁棒性与适应性。

33,316

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 新手乐园
社区管理员
  • 新手乐园社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧