我正在练习我的OOP,我有以下课程:Point和Circle.具体而言,Circle具有中心点和半径.这是相关代码:
// Point.h
class Point
{
public:
Point(double x, double y);
double x() const;
double y() const;
std::string as_string() const;
private:
double x_coord;
double y_coord;
};
// Circle.h
class Circle
{
public:
Circle(const Point& center, double radius);
Point center() const;
double radius() const;
std::string as_string() const;
std::string equation() const;
private:
Point center_pt;
double radius_size;
};
// Circle.cpp
Circle::Circle(const Point& center, double radius)
{
center_pt = center;
radius_size = radius;
}
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试编译此代码时,我收到以下错误:
Circle.cpp: In constructor ‘Circle::Circle(const Point&, double)’:
Circle.cpp:3: error: no …Run Code Online (Sandbox Code Playgroud) 在 C# 中工作,我想启动一个进程并在默认文本编辑程序中打开一个文件,这不一定是该文件类型的默认程序关联。
例如,假设我想打开一个 html 文件。该文件的默认关联可能是 firefox。如何在默认文本编辑器(例如 Notepad、Notepad++ 等)中打开它?
谢谢你的帮助。
编辑:下面的评论说没有办法设置默认的文本编辑程序。很好,有没有办法假装文件是txt文件?
我正在开发一个带有两个命令行参数的程序.两个参数都应该是yyyy-mm-dd形式的日期.由于其他人将使用此程序并且它将从mysql请求,我想确保命令行参数有效.我最初的想法是循环传入字符串的每个元素并对其执行某种测试.' - '很容易检查,但我不太确定如何处理数字,并在int和chars之间区分它们.另外,我需要第一个日期是"小于或等于"第二个,但我很确定我可以处理它.
如果我有一个带有地图的类作为私人成员,例如
class MyClass
{
public:
MyClass();
std::map<std::string, std::string> getPlatforms() const;
private:
std::map<std::string, std::string> platforms_;
};
MyClass::MyClass()
:
{
platforms_["key1"] = "value1";
// ...
platforms_["keyN"] = "valueN";
}
std::map<std::string, std::string> getPlatforms() const
{
return platforms_;
}
Run Code Online (Sandbox Code Playgroud)
在我的主要功能中,这两段代码会有区别吗?
代码1:
MyClass myclass();
std::map<std::string, std::string>::iterator definition;
for (definition = myclass.getPlatforms().begin();
definition != myclass.getPlatforms().end();
++definition){
std::cout << (*definition).first << std::endl;
}
Run Code Online (Sandbox Code Playgroud)
代码2:
MyClass myclass();
std::map<std::string, std::string> platforms = myclass.getPlatforms();
std::map<std::string, std::string>::iterator definition;
for (definition = platforms.begin();
definition != platforms.end();
++definition){
std::cout << (*definition).first << std::endl; …Run Code Online (Sandbox Code Playgroud) I would like to find the first time an element occurs for the second time in a list. For example, if my list was
['1','2','1B','2B','2B','2','1B','1']
Run Code Online (Sandbox Code Playgroud)
the result should be '2B' (or it could return the index 4), since the element '2B' is the first element to occur twice (going left to right).
I know I can do this with a basic for loop counting occurrences as I go along; I just wondered what's the most efficient way to do it.