由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - Why should i include .cpp instead of .h
相关主题
为什么在overloading中,friend <<不能读取private值呢?please help debug this code
c++小问题namespace 问题
about namespaceglobal variable usage question in C++
一个关于C++ template和overload的问题overriding operator<<
请问关于overloading <<弱问c++里有没有NULL这个keyword?
小问题问个C++的问题 friend operator
[合集] 关于template和inheritance的问题请教又一个初级问题: C++中多如牛毛的#define格式
[合集] 怎样有效的传递C静态数组的变量名?弱问C++一个问题 一直不解
相关话题的讨论汇总
话题: complex话题: ostream话题: include话题: operator话题: rhs
进入Programming版参与讨论
1 (共1页)
g*******s
发帖数: 59
1
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
P********e
发帖数: 2610
2
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:

t****t
发帖数: 6806
3
"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);

P********e
发帖数: 2610
4
I mean this,
complex c;
My bad english

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

g*******s
发帖数: 59
5
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);

1 (共1页)
进入Programming版参与讨论
相关主题
弱问C++一个问题 一直不解请问关于overloading <<
问低级问题小问题
C 里面有办法永久改变一个指针的属性吗?[合集] 关于template和inheritance的问题请教
为什么不能成功排序[合集] 怎样有效的传递C静态数组的变量名?
为什么在overloading中,friend <<不能读取private值呢?please help debug this code
c++小问题namespace 问题
about namespaceglobal variable usage question in C++
一个关于C++ template和overload的问题overriding operator<<
相关话题的讨论汇总
话题: complex话题: ostream话题: include话题: operator话题: rhs