作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
<分区>
我正在尝试实现一个返回该类实例的方法,但它在第一次尝试创建实例时崩溃了。我不知道如何在C++/QT中实现单例
主要
#include <QCoreApplication>
#include "carro.h"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
Carta* nueva;
nueva->getInstance();
nueva->setColor("rojo");
cout << nueva->getColor() << endl;
return a.exec();
}
卡罗.h
#ifndef CARRO_H
#define CARRO_H
#include <string>
#include <iostream>
using namespace std;
class Carta{
private:
string cara; //valor
string palo; //simbolo
string color;
string direccion;
static Carta* m_instance;
public:
//constructor
Carta(){
}
static Carta* getInstance(){
if(!m_instance){
m_instance = new Carta;
}
return m_instance;
}
string getDireccion(){
return direccion;
}
void setColor(string pcolor){
color = pcolor;
}
string getColor(){
return this->color;
}
string getPalo(){
return this->palo;
}
string getCara(){
return this->cara;
}
//print
string print(){
return (cara + " de " + palo + " Color: "+color);
}
};
#endif // CARRO_H
我最近购买了《C 编程语言》并尝试了 Ex 1-8这是代码 #include #include #include /* * */ int main() { int nl,nt,nb;
早上好!我有一个变量“var”,可能为 0。我检查该变量是否为空,如果不是,我将该变量保存在 php session 中,然后调用另一个页面。在这个新页面中,我检查我创建的 session 是否为空,
我正在努力完成 Learn Python the Hard Way ex.25,但我无法理解某些事情。这是脚本: def break_words(stuff): """this functio
我是一名优秀的程序员,十分优秀!