Redian新闻
>
Why should i include .cpp instead of .h
avatar
g*s
2
Three files:
complex.h
#ifndef COMPLEX_H
#define COMPLEX_H
#include
using namespace std;
template
class Complex{
friend ostream & operator << (ostream &output, const Complex &rhs);
private:
T real;
T imaginary;

public:
explicit Complex(T x, T y):real(x),imaginary(y){}
~Complex(){}
Complex & operator +(const Complex &rhs) const;
.
.
.
};
#endif
complex.cpp
#include "complex.h"
using namespace std;
template
ostream & operator
avatar
P*e
3
where did you get this code?
For templates, place all the non-inline member function definition in the .h
file. This seems contrary to ordinary, but for templates, those member
function will not be compiled and will be waiting for run-time type define.
I don't know if this will help, but at least, you can get something right.

rhs);

【在 g*******s 的大作中提到】
: Three files:
: complex.h
: #ifndef COMPLEX_H
: #define COMPLEX_H
: #include
: using namespace std;
: template
: class Complex{
: friend ostream & operator << (ostream &output, const Complex &rhs);
: private:

avatar
t*t
4
"run-time type define"...
i don't think C++ provides this

.h

【在 P********e 的大作中提到】
: where did you get this code?
: For templates, place all the non-inline member function definition in the .h
: file. This seems contrary to ordinary, but for templates, those member
: function will not be compiled and will be waiting for run-time type define.
: I don't know if this will help, but at least, you can get something right.
:
: rhs);

avatar
P*e
5
I mean this,
complex c;
My bad english

【在 t****t 的大作中提到】
: "run-time type define"...
: i don't think C++ provides this
:
: .h

avatar
g*s
6
3x. i write these codes myself.
I was thinking to write them in a .cpp as usual but i fail
to know template function would be better put inside one .h file.

.h

【在 P********e 的大作中提到】
: where did you get this code?
: For templates, place all the non-inline member function definition in the .h
: file. This seems contrary to ordinary, but for templates, those member
: function will not be compiled and will be waiting for run-time type define.
: I don't know if this will help, but at least, you can get something right.
:
: rhs);

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。