解决基本问题 [英] Basic problem solving

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

问题描述

在我新开发的Visual C ++ 6项目中,我基于CDialog基类派生了大约4个新类。在后面的阶段,我需要添加一个大量的CString类型变量。 (行号超过4600)当我在现有的类头文件中声明它们时,似乎超出了编译器限制。无法用2或3标准限制编译完成。然后我通过项目插入 - 头文件创建了一个新的头文件,使用#def MYHEADER.H,也尝试了#ifndef cplusplus #def等。将所有新的变量声明放在该文件中。但编译器在生成代码处停止。我进一步工作,分裂声明是小头文件。我试过#pragma pack(n)。但一切都停止了。有人可以解决这个问题。

解决方案

首先,你不要在头文件中声明变量。


头文件是仅包含声明而不包含定义。


声明说存在的东西。

定义创建它。


头文件中的变量通常是全局变量。如果是这样,程序中的全局内存有限制。这可能导致一个包含大量全局变量的程序无法构建。


每次包含标题时都会创建头文件中的变量。当同一范围内有许多同名变量时,这会导致链接器失败。

在函数中声明为局部变量的变量进入函数堆栈帧。在这里,堆栈内存可能会限制在运行时使程序崩溃。


你需要:


1)删除来自头文件的所有变量。

2)使用 new 运算符自行分配4600 CStrings。这将把字符串放在堆上,实际上没有大小限制。

3)你完成它们后删除字符串。


这个将允许您通过指针或引用传递字符串。



首先,您不要在头文件中声明变量。


头文件只包含声明而不包含定义。



1s / declare / define /


亲切的问候,


Jos (< --- nitpicker; - )



1s / declare / define /



Dang!我的意思是不定义。我在想定义。但是你只在头文件中声明,这就是我输入的内容。吉兹!


In my new developed Visual C++ 6 project I derived about 4 new classes based upon CDialog base class. In later stage I required to add a greate number of CString type variables. (the line numbers exceeded 4600) When I declared them in a existing Class header file, it seems the the compiler limit exceeded. Could not compile with 2 or 3 standard limite completes. Then I created a new header file through ''project insert - header file'', with #def MYHEADER.H, also tried #ifndef cplusplus #def etc. Put all new variable declaration in that file. But compiler halts at "Generating Code". I worked further, splitted declarations is small header files. I tried #pragma pack(n). But all is halted. Could somebody solve this problem.

解决方案

First, you do not declare variables in a header file.

Header files are to contain only declarations and not definitions.

A declaration says a thing exists.
A definition creates it.

Variables in header files are usually global variables. If so, there is a limit to global memory in a program. That can cause a program with a lot of globals tto not build.

Variables in header files are created each time the header is included. This can cause the linker to fail when there are many variables with the same name in the same scope.

Variables declared in functions as local variables go into the functions stack frame. Here again, there may ne limits to stack memory that will crash your program at run time.

You need to:

1) remove all variables from your header files.
2) allocate your 4600 CStrings yourself using the new operator. That will put the strings on the heap where there is effectively no size limit.
3) you delete the strings when you are finished with them.

This will let you pass the strings around by pointer or reference.


First, you do not declare variables in a header file.

Header files are to contain only declarations and not definitions.

1s/declare/define/

kind regards,

Jos (<--- nitpicker ;-)


1s/declare/define/

Dang! I mean''t define. I was thinking define. But you only declare in a header file so that''s what I typed. Geez!


这篇关于解决基本问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆