是否可以避免在实现文件中重复类名? [英] Is it possible to avoid repeating the class name in the implementation file?
问题描述
有没有办法避免在实现文件中的 Graph ::
重复,但仍然将类拆分成header +实现?例如:
标头档案:
#ifndef Graph_H
#define Graph_H
类图{
public:
Graph(int n);
void printGraph();
void addEdge();
void removeEdge();
};
#endif
实施文件:
Graph :: Graph(int n){}
void Graph :: printGraph(){}
void Graph :: addEdge {}
void Graph :: removeEdge(){}
我猜这是为了避免大量的不必要的打字。可悲的是,没有办法摆脱范围(因为许多其他答案已告诉你)但是我个人的做法是将所有我的函数原型定义在漂亮的行,然后复制/粘贴到实现文件然后ctrl-c您的ClassName ::在剪贴板和运行与ctrl-v。
行
Is there a way to avoid the Graph::
repetition in the implementation file, yet still split the class into header + implementation? Such as in:
Header File:
#ifndef Graph_H
#define Graph_H
class Graph {
public:
Graph(int n);
void printGraph();
void addEdge();
void removeEdge();
};
#endif
Implementation File:
Graph::Graph(int n){}
void Graph::printGraph(){}
void Graph::addEdge(){}
void Graph::removeEdge(){}
I'm guessing this is to avoid lots of "unnecessary typing". Sadly there's no way to get rid of the scope (as many other answers have told you) however what I do personally is get the class defined with all my function prototypes in nice rows, then copy/paste into the implementation file then ctrl-c your ClassName:: on the clip board and run up the line with ctrl-v.
这篇关于是否可以避免在实现文件中重复类名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!