我写了这样的东西:
class Storage
{
public:
Storage();
QString key() const;
int value() const;
void add_item(QString&,int);
private:
QMap<QString,int>* my_map_;
};
void Storage::add_item(QString& key,int value)//------HERE IS THE SLOT FOR ADDING
{
*my_map_[key] = value;
}
Run Code Online (Sandbox Code Playgroud)
当我试图通过以下方式添加项目时QMap:
class Dialog : public QDialog
{
Q_OBJECT
public:
Dialog(QWidget* = 0);
public slots:
void add_item()
{
strg_->add_item(ui->lineEdit->text(),ui->spinBox->value());//---HERE I'M "PASSING" TWO OBJECTS: QString AND int
ui->lineEdit->clear();
}
private:
Ui::Dialog* ui;
Storage* strg_;
};
Run Code Online (Sandbox Code Playgroud)
我收到错误:
error: no matching function for call to 'Storage::add_item(QString, int)
note: candidates are: …Run Code Online (Sandbox Code Playgroud) 我想将一个现有的字符串转换为枚举(不作为枚举读取).我怎样才能做到这一点?
C#编译器抱怨包含以下代码new protected member declared in struct.问题是什么?
struct Foo {
protected Object _bar;
}
Run Code Online (Sandbox Code Playgroud) 我是Rails的新手,所以如果我的问题没有最有意义,我会道歉.
我有一个名为的类PaymentGatewayCipher看起来像:
require 'openssl'
# Encapsulates payment gateway encryption / decryption utility functions
class PaymentGatewayCipher
class << self
def encrypt(file, options = {})
cipher = create_cipher
cipher.encrypt(cipher_key)
data = cipher.update(File.read(file))
data << cipher.final
if to_file = options[:to]
# Write it out to a different file
File.open(to_file, 'wb') do |f|
f << data
end
end
data
end
# Decrypts the given file
def decrypt(file)
cipher = create_cipher
cipher.decrypt(cipher_key)
encrypted_data = File.open(file, 'rb') {|io| io.read}
data = cipher.update(encrypted_data)
data << …Run Code Online (Sandbox Code Playgroud) 我使用 postgresql 作为我的后端数据库。
尝试扫描一个languagespoken文本数组字段
var user userprofile
row := core.db.QueryRow(
"SELECT languagespoken FROM \"user\" WHERE id = $1",
userId,
)
err := row.Scan(&user.Languages)
if err != nil {
return user, err
}
Run Code Online (Sandbox Code Playgroud)
我的结构看起来像这样
type userprofile struct {
Languages []string `json:languages`
}
Run Code Online (Sandbox Code Playgroud)
但出现错误
2014/06/30 15:27:17 PANIC: reflect.Set: **value of type []uint8 is not assignable to type []string**
/usr/lib/go/src/pkg/reflect/value.go:2198 (0x56c152)
Value.assignTo: panic(context + ": value of type " + v.typ.String() + " is not assignable to type " + dst.String()) …Run Code Online (Sandbox Code Playgroud) 我注意到Vala不允许你const从非const变量初始化变量.为什么是这样?这是故意的设计决定还是错误/遗漏?分别考虑这些Vala和C示例; 在C程序编译并按预期运行时,Vala程序无法编译:
void main()
{
const int constInt = 1;
const int a = constInt;
int plainInt = 0;
const int b = plainInt;
stdout.printf("A: %d\n", a);
stdout.printf("B: %d\n", b);
}
// Compiler output:
// test.vala:7.18-7.25: error: Value must be constant
// const int b = plainInt;
// ^^^^^^^^
Run Code Online (Sandbox Code Playgroud)
#include <stdio.h>
int main()
{
const int constInt = 1;
const int a = constInt;
int plainInt = 0;
const int b = plainInt;
printf("A: …Run Code Online (Sandbox Code Playgroud) 我正试图在Genie中列出一个列表并且它似乎不起作用.编译代码:
[indent=2]
init
var l = new list of string
Run Code Online (Sandbox Code Playgroud)
产生这些错误:
someone@someone-UBook:~/Documents$ valac helloworld.gs helloworld.gs:2.10-2.24: error: The name `Gee' does not exist in the context of `main'
var l = new list of int
^^^^^^^^^^^^^^^
helloworld.gs:2.8-2.24: error: var declaration not allowed with non-typed initializer
var l = new list of int
^^^^^^^^^^^^^^^^^
Compilation failed: 2 error(s), 0 warning(s)
Run Code Online (Sandbox Code Playgroud)
我已经安装了libgee2(通过sudo apt-get install libgee2),没有任何改变.有任何想法吗?
我试图覆盖基类中另一个方法使用的基类的方法; 但是,当派生类调用基类的using方法时,派生的used-method永远不会被执行,而是调用基类的used-method.这是一个例子:
#include <iostream>
using namespace std;
class Base {
public:
Base() {}
virtual ~Base() {}
void printLeft() { cout << this->getLeft(); }
int getLeft() { return 0; }
};
class Derived: public Base {
public:
Derived() {}
virtual ~Derived() {}
int getLeft() { return 1; }
};
int main(int argc, char *argv[]) {
Derived d = Derived();
d.printLeft();
}
Run Code Online (Sandbox Code Playgroud)
运行main()打印0,指示使用Base的getLeft()方法而不是派生对象的方法.
如何更改此代码,以便在从Derived实例Derived::getLeft()调用时调用?
我正在尝试使用Intent发送sdcard文件夹中包含的文件(.log文件).这是代码:
public void sendMail() {
Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_EMAIL, new String[] {"name.surname@gmail.com"});
intent.putExtra(Intent.EXTRA_SUBJECT, "Log files");
intent.putExtra(Intent.EXTRA_TEXT, "body");
//has to be an ArrayList
ArrayList<Uri> uris = new ArrayList<Uri>();
//convert from paths to Android friendly Parcelable Uri's
if(Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())){
File root = Environment.getExternalStorageDirectory();
File logfolder = new File(root, "log");
for (String file : logfolder.list()){
Uri u = Uri.parse(file);
uris.add(u);
}
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
startActivity(Intent.createChooser(intent, new String("Send mail...")));
}
}
Run Code Online (Sandbox Code Playgroud)
我从菜单中选择Gmail.Gmail打开后,会正确显示包含收件人,主题,文本和附件的邮件.邮件被发送没有错误,但我收到状态栏通知,说"无法显示附件"!事实上,收件人正确收到电子邮件但没有附件.我无法弄清问题是什么.为什么附件没有被发现?请帮我!!
我发现字节godoctype byte byte非常混乱,不应该是?type byte uint8
byte是uint8的别名,在所有方面都等同于uint8.按照惯例,它用于区分字节值和8位无符号整数值.type complex128
c++ ×2
go ×2
vala ×2
ada ×1
android ×1
c# ×1
enums ×1
genie ×1
inheritance ×1
libgee ×1
polymorphism ×1
postgresql ×1
qt ×1
rake-task ×1
string ×1