我在将属于类'F‘的函数传递给属于类’X‘的函数时遇到了一些问题。我收到错误消息' error : no match function for call to X::call()’对不起,如果解决方案真的很简单,我仍然是C++的新手
我的代码:
#include <iostream>
using namespace std;
class X{
public:
void call (void (*func)()){
func();
}
};
class F{
public:
void Function(){
我在一个c++类中使用了一个c++。其中一个成员函数应调用以下函数,该函数生成中断并调用服务例程:
signed short __stdcall SetIrqConditions
(
signed short DevNum,
unsigned short bEnable,
unsigned int dwIrqMask,
void (__stdcall * funcExternalIsr)
(
signed short DevNum,
unsigned int dwIrqStatus
)
);
我正在尝试调用与此函数
我在C++中有以下结构:
class A
{
protected:
int a;
};
class B : public A
{
public:
static void initThreads(); //Initialize threads (pthreads)
/* Threads */
static void* send(void*);
static void* receive(void*);
}
这些函数“发送”和“接收”操作在"a“上。但不能在静态函数中编辑非静态成员。由于发送和接收都是线程,因此需要将它们定义为静态。我将只有一个类B的对象,尽管有多个类
我从许多其他堆栈溢出线程(如)中了解到,模板参数是在编译时计算的。此外,非类型模板参数应该是一个常量表达式、积分表达式或指向具有外部链接的对象的指针。
而且,我在Makefile中的g++命令中没有使用--std=c++0x。
那么,是否可以实例化作为参数传递为NULL的模板类?
// I have a template class like this -
template<class T, T invalidVal, int e> class A
{
static inline bool dummy(T value)
{
return 0;
我们有一个接受C函数指针的结构:
int one(int x)
{
}
int two(int x)
{
}
struct Cstruct
{
int (*fn1)(int);
int (*fn2)(int);
};
现在我有了一个C++类,它的方法如下:
class A
{
public:
int one(int x)
{
}
int two(int x)
{
}
int three(int x)
{
struct Cstruct cstr = {&this->one, &a
我有以下问题:
void MyClass::LoopFunction(vector<Item>& items,void (MyClass::*funcy)(vector<Item>&,int))
{
for(SInt32 i = 0; i < 50; i++)
{
funcy(items,i);
}
}
上面写着:
Called object type 'void(MyClass::*)(vector<Item>&,int)' is not a function or f
在C++中,我有很多函数(一、二、三……)它看起来像这样:
int MyClass::one(Mynamespace::Data* data)
{
//do something
return 0;
}
我还有一个动作函数,我想用它来调用一,二,三…具有函数指针的函数。
int MyClass::action(Mynamespace::Data* data)
{
int (*actionFunction)(Mynamespace::Data*);
actionFunction = data->name; // the name is a string wit
我在C++中发现了一件有趣的事情。
using namespace std;
struct Person {
string name;
bool check() {
return name == "carol";
}
};
int main()
{
Person p = { "Mark" };
list<Person> l;
l.push_back(p);
if (find_if(l.begin(), l.end(), bind(&Person::check, s
我正在学习OOP C++编程背后的一些理论。我们的教授给我们提供了一些试题样本,这样我们就可以在考试前复习。请你看一看,看看我对这个词的理解是否正确。我真的很感谢你的建议。
The this keyword:
a) Inside a constructor, it is a reference to currently constructed object. (false)
b) In the method, it is a reference to the object for which it was called (true)
c) Inside the constructor it i
我的模型如下
using namespace v8;
using namespace node;
class A {
private:
//something
public:
//something
}
class X {
private:
A* a;
public:
X() {
a = new A();
}
Handle<Value> myfunc(const Arguments& args) {
//I want to access the instance's &
我刚刚发现了一些C++代码(在,它使用了一种我以前从未见过的技术将类型添加到现有的类中:
class Testpm {
public:
void m_func1() { cout << "m_func1\n"; }
int m_num;
};
// Define derived types pmfn and pmd.
// These types are pointers to members m_func1() and m_num, respectively.
void (Testpm::*pmfn)() = &Testpm::m_func1
我试图创建一个速度、距离和时间计算器,这是尽可能有效的,并希望引用调用一个函数,使用指针根据输入变化,但不确定如何这样做。我尝试过许多不同的东西:
我最好的尝试:
// Inside class Math
double calcSpeed(double distance, double time); // These functions return a double value of the formula (non static)
double calcDistance(double speed, double time);
double calcTime(double speed, do
当我试图使用声明为类变量的map 'freq‘的内容时,在比较器函数中对向量进行排序(使用map按频率排序)时,我遇到了这个错误。有谁能指出我哪里出了问题,我该怎么做?下面是代码:
class Solution {
map<int, int> freq;
public:
static bool comp(int a, int b){
if(a!=b){
int c1 = freq[a];
int c2 = freq[b];
if(c1!=c2)
在下面的C++程序中,从函数修改静态数据成员const可以正常工作:
class A
{
public:
static int a; // static data member
void set() const
{
a = 10;
}
};
但是,从const函数修改非静态数据成员不起作用:
class A
{
public:
int a; // non-static data member
void set() const
{
a = 10;
}
};
为什么const
很抱歉问这样一个问题,因为我相信以前已经回答过了,但我正在努力寻找答案,这不是为了看起来不够……不管怎样..。
class foo
{
void read(void (*func)(obj&))
{
// many things happen to obj...
(*func)(obj); // Calls the function pointer to the handler.
}
};
class bar : public foo
{
void handler(obj&)
{
/
我在一个类中创建四个线程时遇到了困难,每个线程使用另一个成员函数打印出每个向量的内容。然而,当我创建线程时,我在这4行上得到了一个错误no instance of constructor "std::thread::thread" matches the argument list。如果我试图为线程使用另一个成员函数,我不知道为什么它不能工作。难道是因为他们在一个类里吗?我该如何纠正这4个错误?
class PrintfourVectors
{
private:
vector<string> one;
vector<string> two
我正在用c++写我自己的计时器。我想知道是否有可能将一个函数传递给计时器构造函数,然后调用这个函数。
我正在考虑为此使用函数指针,但是我无法找到在类本身内传递非静态函数的解决方案。
G++给出了这个错误:
Server.cpp:61:54:错误:无效使用非静态成员函数serverTimer =新计时器::Timer(onTimerTick,3000);
我的类Server.cpp如下所示:
private:
void onTimerTick(){
//do something with class variables, so can't us
下面给定的代码成功地编译:
template <typename T, T nontype_param>
class C;
class X {
public:
int n;
};
int main()
{
C<int X::*, &X::n>* c; //Here
return 1;
}
在这里,范围分辨率操作符是如何工作的,而不是. operator呢?我们可以访问这样的非静态成员吗?
参考: C++模板完整指南8.3.3节非类型参数