33,311
社区成员
发帖
与我相关
我的任务
分享
//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;
}
//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;
}