线程错误
嘿伙计们,我在这段代码上遇到了一些麻烦。我不认为这有什么问题。但它给了我错误,例如
hw2.cpp:35: error: request for member 'max2' in 'my_data', which is of non-class type 'thread_data*' hw2.cpp:35:错误:请求“my_data”中的成员“max”,该成员属于非类类型“thread_data*” hw2.cpp:36:错误:请求“my_data”中的成员“max”,该成员属于非类类型“thread_data*” hw2.cpp:39:错误:请求“my_data”中的成员“max2”,该成员属于非类类型“thread_data*” hw2.cpp:40:错误:请求“my_data”中的成员“max2”,该成员属于非类类型“thread_data*”
struct thread_data
{
char *file_name;
int max;
int max2;
};
struct thread_data thread_data_array[NUM_THREAD];
void *FindNum(void *threadArg)
{
int in_num;
struct thread_data *my_data;
my_data = (struct thread_data *) threadArg;
file.open (my_data.file_name);
if (file.is_open())
cout << "file can not be file"<<endl;
while (!file.eof())
{
file >> in_num;
if (in_num > my_data.max){
my_data.max2 = my_data.max;
my_data.max = in_num;
}
else if (in_num > my_data.max2){
my_data.max2 = in_num;
}
}
pthread_exit(NULL);
}
Hey guys I am having a little trouble with this bit of code. I dont see anything wrong with it. but it is giving me errors such as
hw2.cpp:35: error: request for member ‘max2’ in ‘my_data’, which is of non-class type ‘thread_data*’
hw2.cpp:35: error: request for member ‘max’ in ‘my_data’, which is of non-class type ‘thread_data*’
hw2.cpp:36: error: request for member ‘max’ in ‘my_data’, which is of non-class type ‘thread_data*’
hw2.cpp:39: error: request for member ‘max2’ in ‘my_data’, which is of non-class type ‘thread_data*’
hw2.cpp:40: error: request for member ‘max2’ in ‘my_data’, which is of non-class type ‘thread_data*’
struct thread_data
{
char *file_name;
int max;
int max2;
};
struct thread_data thread_data_array[NUM_THREAD];
void *FindNum(void *threadArg)
{
int in_num;
struct thread_data *my_data;
my_data = (struct thread_data *) threadArg;
file.open (my_data.file_name);
if (file.is_open())
cout << "file can not be file"<<endl;
while (!file.eof())
{
file >> in_num;
if (in_num > my_data.max){
my_data.max2 = my_data.max;
my_data.max = in_num;
}
else if (in_num > my_data.max2){
my_data.max2 = in_num;
}
}
pthread_exit(NULL);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嗯,
my_data
是一个指向结构的指针,而不是一个结构。您必须使用取消引用(*
)它才能获取结构。尝试:基本上
my_data->max2
是(*my_data).max2
的语法糖。Well,
my_data
is a pointer to a structure, not a structure. You have to use dereference (*
) it to get to the structure. Try:Basically
my_data->max2
is syntactic sugar for(*my_data).max2
.