我在使用C++函数指针时遇到问题.这是我的例子:
#include <iostream>
using namespace std;
class bar
{
public:
void (*funcP)();
};
class foo
{
public:
bar myBar;
void hello(){cout << "hello" << endl;};
};
void byebye()
{
cout << "bye" << endl;
}
int main()
{
foo testFoo;
testFoo.myBar.funcP = &byebye; //OK
testFoo.myBar.funcP = &testFoo.hello; //ERROR
return 0;
}
Run Code Online (Sandbox Code Playgroud)
Compilator在testFoo.myBar.funcP = &testFoo.hello;以下位置返回错误:
ISO C++禁止获取绑定成员函数的地址以形成指向成员函数的指针.说'&foo :: hello'
无法在赋值时将'void(foo :: )()'转换为'void()()'
所以我试着这样:
class bar
{
public:
void (*foo::funcP)();
};
Run Code Online (Sandbox Code Playgroud)
但是现在编译器增加了一个:
'foo'尚未宣布
有没有办法让它发挥作用?
提前感谢您的建议
我正在为我的图表使用' System.Windows.Forms.DataVisualization.Charting '库,我想知道是否有人想出如何切换轴以垂直显示图表
谢谢.

在makefile中,我在构建目录中构建了所有.o文件:
program: class1.o class2.o class3.o
g++ $(BUILDDIR)class1.o $(BUILDDIR)class2.o $(BUILDDIR)class3.o -o $@
Run Code Online (Sandbox Code Playgroud)
$(BUILDDIR)class1.o $(BUILDDIR)class2.o $(BUILDDIR)class3.o从依赖列表生成会很酷......
我知道这$^会给我所有依赖项的列表,用空格分隔,但我不能处理子目录.
可能吗 ?
如果我有program: class1.o class2.o class3.o configure,我可以configure从列表中排除吗?
谢谢 :)
编辑:迈克尔的解决方案效果很好,但这样做,make没有找到的依赖关系和具有每次建立一切......是不是有一个更简单的方法,使得当潜规则一样program: class1.o class2.o class3.o,告诉它把二进制文件在构建目录?
我认为两者都是有效的C语法,但哪个更好?
一个)
void func(int a[]); // Function prototype
void func(int a[]) { /* ... */ } // Function definition
Run Code Online (Sandbox Code Playgroud)
要么
B)
#define ARRAY_SIZE 5
void func(int a[ARRAY_SIZE]); // Function prototype
void func(int a[ARRAY_SIZE]) { /* ... */ } // Function definition
Run Code Online (Sandbox Code Playgroud) 我通过jquery提交了一个表单,但是我需要ActionResult来返回true或false.
这是控制器方法的代码:
[HttpPost]
public ActionResult SetSchedule(FormCollection collection)
{
try
{
// TODO: Add update logic here
return true; //cannot convert bool to actionresult
}
catch
{
return false; //cannot convert bool to actionresult
}
}
Run Code Online (Sandbox Code Playgroud)
我如何设计我的JQuery调用来传递表单数据,并检查返回值是true还是false.如何编辑上面的代码以返回true或false?
我在has_one关系中遇到accepts_nested_attributes_for时遇到问题.
模特:购买和销售.
class Purchase < ActiveRecord::Base
has_one :sale, :dependent => :destroy
accepts_nested_attributes_for :sale
end
class Sale < ActiveRecord::Base
belongs_to :purchase
end
Run Code Online (Sandbox Code Playgroud)
在控制器/新动作中:
@purchase = Purchase.new(
:club_id => @club.id,
:subcategory_id => subcategory.id
)
Run Code Online (Sandbox Code Playgroud)
在视图(HAML)中:
- form_for(@purchase) do |f|
# some fields for purchase
- f.fields_for :sale do |s|
= s.text_field :amount, :size => 6
# and so on
Run Code Online (Sandbox Code Playgroud)
问题:这实际上并没有在我的视图中呈现任何待售的输入框.购买字段呈现正常,但销售字段不会出现.
如果我将此行添加到控制器:
@purchase.sale.build
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
class Purchase < ActiveRecord::Base
has_many :sales, :dependent => :destroy
accepts_nested_attributes_for :sales
end
Run Code Online (Sandbox Code Playgroud)
为了使事情变得更奇怪,如果我将关联类型更改为has_many而不是has_one,从而创建:
class Purchase < ActiveRecord::Base
has_one :sale, …Run Code Online (Sandbox Code Playgroud) 是否有GWT(Google Web Toolkit)的功能可以打印小部件的html输出?(如果问题严重错误,我道歉 - 我不是GWT开发者,但我们的开发人员声称没有办法做到这一点)
目前所有输出都是一个巨大的单行块,因此调试CSS问题等是一项相当大的任务.
HTML Tidy/Pretty Print,至少在测试期间,将是一个很好的帮助.
我想用C#和F#编写一些东西.我有部分类,我想在其中一些中定义F#方法.我得到的问题是,部分类不能跨越2个DLL.有没有办法合并它们?我更喜欢免费的解决方案,并且能够在正常构建中自动完成.
c# ×2
asp.net-mvc ×1
bar-chart ×1
c ×1
c++ ×1
charts ×1
class ×1
dependencies ×1
dll ×1
f# ×1
g++ ×1
guava ×1
gwt ×1
htmltidy ×1
java ×1
jquery ×1
makefile ×1
php ×1
pretty-print ×1
subdirectory ×1