本文介绍了C STRUCTURE DLL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我是C编程的新手。

Hello everyone, I'm a newbie in C Programming.

我正在学习如何声明一个结构的指针数组,但我不知道如何。

I'm learning how to declare a pointer array of structure, but I don't know how.

这就是我的代码的样子,我做得对吗?

This is how my code look like, Am I doing it right?

#ifdef STUDENTFUNCSDLL_EXPORTS
#define STUDENTFUNCSDLL_API __declspec(dllexport) 
#else
#define STUDENTFUNCSDLL_API __declspec(dllimport) 
#endif


namespace StudentFuncs
{
	class sampleStudentFuncs
	{
	public:
		typedef struct student *student;
		STUDENTFUNCSDLL_API struct student AddStudent(student *student);
	};
}


我不知道怎么再打电话了。任何评论将不胜感激。谢谢:)
$

I don't know how to call it anymore. Any comment would be appreciated. Thank you :)

推荐答案

您的代码有一些问题。

   typedef声明隐式声明struct student类型的不完整对象。  在C ++中,您可以将此类型称为"struct student"。或者只是简单地说"学生"。

   声明然后继续指定类型"学生"。是"struct student *"类型的别名。 当编译器遇到类型"学生"时在声明或定义中(例如AddStudent的原型
),它应该知道你是否意味着"结构学生"是什么意思?或"结构学生*"?

   The typedef declaration implicitly declares an incomplete object of type struct student.  In C++, you can refer to this type either as "struct student" or simply "student".
   The declaration then goes on to specify that the type "student" is an alias for the type "struct student *".  When the compiler encounters the type "student" in a declaration or definition (such as the prototype for AddStudent), how is it supposed to know whether you mean "struct student" or "struct student *"?

   AddStudent的声明将返回类型指定为struct student。 在代码的这一点上,struct student是一个不完整的类型。 编译器需要知道struct student的内部细节才能使用。

   The declaration for AddStudent specifies the return type as struct student.  At this point in the code, struct student is an incomplete type.  The compiler needs to know the internal details of struct student for this to work.

通常,特别是对于新学生练习,处理一组struct的常用过程是声明一个单独的  ;指向struct的指针并使用 初始化它,或者为其指定数组中第一个结构的地址。 你可以
然后使用普通的下标符号,指针[index]来访问数组中的任何元素。

Normally, especially for new student exercises, the usual procedure for dealing with an array of struct is to declare a single pointer to struct and initialize it with or assign to it the address of the first struct in the array.  You can then use normal subscript notation, pointer[index], to access any element in the array.


这篇关于C STRUCTURE DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 22:05