Chinaunix首页 | 论坛 | 博客
  • 博客访问: 932383
  • 博文数量: 158
  • 博客积分: 4380
  • 博客等级: 上校
  • 技术积分: 2367
  • 用 户 组: 普通用户
  • 注册时间: 2006-09-21 10:45
文章分类

全部博文(158)

文章存档

2012年(158)

我的朋友

分类: C/C++

2012-11-20 11:26:05

// a.hpp
struct foo
{
    foo();
#ifdef SOMETHING
    int a;
#endif
    int b;
};

// a.cpp
#define SOMETHING
#include "a.hpp"
#undef SOMETHING
foo::foo()
{
     a = 1;
     b = 2;
}

// main.cpp
#include "a.hpp"
#include
int main()
{
    foo test;                         // 理论上讲,a.cpp和main.cpp中的foo定义不同,是不同的类型,所以应当报foo()未实现,但实际上却正确
    std::cout << test.b << std::endl; // 输出1
}

------------------------------------------------------------------------------------
在VC2005中:
#include
#include
#include

int main( void )
{
    std::locale prev_loc = std::locale::global( std::locale("chs") ); // 没有这一句的话,文件打开失败
    std::ifstream file( "d:\\测试" );
    std::locale::global( prev_loc ); // 没有这一句的话,文件中的中文无法输出,且wcout输出中文也失败

    for( std::string line; getline(file,line); )
    {
        std::cout <<  line << std::endl;
    }

    std::wcout.imbue( std::locale("chs") );
    std::wcout << L"结束" << std::endl;
}

------------------------------------------------------------------------------------
template
struct a
{
    void foo( void ) {}
};
template
struct b : a

    void bar( void ) { foo(); } // g++3.4.2不能编译通过,必须写成 a::foo();
};

------------------------------------------------------------------------------------
template
struct foo
{
    template
    void bar( void )
    {
    }
};

template
void test( void )
{
    foo().bar();
    foo().bar(); // g++3.4.2不能编译通过,必须写成
foo().template bar();
}

阅读(800) | 评论(2) | 转发(0) |
给主人留下些什么吧!~~

网友评论2012-11-20 11:26:53

周星星
#include <iostream>
using namespace std;

struct A
{
    int arr[10][10];

    typedef int (*PARR)[10];
    operator PARR()
    {
        // 如果是VC8,用这句,输出:__thiscall A::operator int (*)[10](*(void))[10]
        cout << __FUNCSIG__ << endl;
        // 如果是GC

网友评论2012-11-20 11:26:42

周星星
#include <stdio.h>
#include <math.h>

int main()
{
      double i = 2;
      int tn = pow(10.0,i);
      
      printf( "%d\n", tn );
      getch();
      return 0;
}

在 dev-cpp4992 下输出为99
pow(10.0,i)的运算结果似乎没错