English 中文(简体)
2. 加工前宏观错误[封闭]
原标题:Stange error with preprocessor macro [closed]
  • 时间:2010-07-25 13:05:33
  •  标签:
  • c++

i have changed code style and aslo i hope it will help http://www.cs.bell-labs.com/cm/cs/pearls/spacemod.cpp

#include <iostream>
using namespace std;

#define MEASURE(T,  text)
{        
   int i;
cout<<text<<"	";                       

 cout<<sizeof(T)<<"	";                     
 int lastp=0;
  for ( i=0;i<11;i++){                
      T *p=new T;                                  
      int thisp=(int)p;                                   
       if (lastp!=0)   cout<<" "<<thisp-lastp;           
       lastp=thisp;                             
  }                                                                     
  cout<<"n";
  }                                                     
  using namespace std;
template <class T>
void measure(char *text)
{
    cout<<"measure"<<text<<"	";  
    cout<<sizeof(T)<<"
";
}
int main(){



     return 0;
}

它只有一个错误。

1>c:usersdaviddocumentsvisual studio 2010projectsmeasuremeasure.cpp(5): error C2447:  {  : missing function header (old-style formal list?)
问题回答

页: 1 线路本身以及<代码>int i;,可能还有该宏观的空线(我不相信这一点)。

我怀疑<条码><>/代码>在您的<条码>前的行文上也有意思。

然而,我所绝对肯定的一点是,如果使用在线功能,比<条码>#define宏观功能更好。

虽然inline don t guarantee,该编码实际上已上网,但我往往总是让编辑选择。

而代号是宏观,我在C++的顶端 heavily着,特别是在复杂情况下,例如:-

你在宏观的第一线上缺乏一条线延续性。 你们可以看到,通过管理加工商(例如,G++使用——E国旗)来扩大你的宏观。

尽管如此,我看不出为什么你首先需要宏观。 为什么不使用简单的模板功能?

Ok, its the continuation character after the #define as you got from the prevoius answears. You should try to avoid defines as far as possible, exactly because they can lead to such errors which don t mean anything. I think you did that define to increase performance, but there is a better way to do this. Define this function as an "inline" function in the header. You can read more about inline functions for example here: http://www.cplusplus.com/doc/tutorial/functions2/





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签