由买买提看人间百态

topics

全部话题 - 话题: endif
首页 上页 1 2 3 4 5 下页 末页 (共5页)
q***s
发帖数: 2243
1
来自主题: Programming版 - 两个class的交叉引用问题
在做一个程序,需要用到两个class的交叉引用,比如在A类中要用到B类的实例,同样在B
类中也需要用到A类的实例,我把两个类是放在两个文件中,分别为a.h, a.cpp, b.h, b.
cpp,但是,问题是我无论如何也不能让编译器认识这是两个类。
请教高手,如何放置头文件才可以实现编译通过。
我的文件大概如下:
文件a.h
#ifndef a_h
#define a_h
class A
{
vector mylist;
}
#endif
文件b.h
#ifndef b_h
#define b_h
class B
{
public:
void print(A aa);
}
#endif
q***s
发帖数: 2243
2
来自主题: Programming版 - 两个class的交叉引用问题
每个cpp文件include他自己的头文件
我在头文件中放进了要用的类的文件,如下
文件a.h
#ifndef a_h
#define a_h
#include "b.h" //好像不行
class A
{
vector mylist;
}
#endif
文件b.h
#ifndef b_h
#define b_h
#include "a.h" //好像这样不行的
class B
{
public:
void print(A aa);
}
#endif
h********r
发帖数: 821
3
近来看比较大的程序,因为缩进做得很不好,让我对那些遥相呼应的if endif,do
enddo不胜其烦。是否有某种编程工具可以自动找到这种if endif,do enddo对?
本人用fortran编程,但是我想所有编程语言工具是类似的。
那位大侠知道请指点一二,不胜感激!
h********r
发帖数: 821
4
俺弄了个土办法,好像也能解决问题。首先把文件中所有的then换成then{,还有endif
换成endif},然后按照5楼大哥指点的用%,然后不管针对indent多烂的code,世界都和
谐了:)
P********e
发帖数: 2610
5
来自主题: Programming版 - 问个C++问题,高手帮帮忙
#ifdef 32_BIT_COMPILER
typedef float floating;
#endif
#ifdef 64_BIT_COMPILER
typedef double floating;
#endif
b********g
发帖数: 404
6
来自主题: Programming版 - 弱问c++里有没有NULL这个keyword?
sorry,我说的MS包装就是MS对windows开发时定义好的意思,
null确实不是关键字,也是被提前定义好的
/* define NULL pointer value */
#ifndef NULL
#ifdef __cplusplus
#define NULL 0
#else
#define NULL ((void *)0)
#endif
#endif
t****t
发帖数: 6806
7
来自主题: Programming版 - 【请教】mpicc 和 mpiCC编译问题
for 2, you probably need to enclose the declaration of fortran/C functions
by
extern "C" { ... }
you can do this:
#ifdef __cplusplus
extern "C" {
#endif
#include .....
#include ....
#ifdef __cplusplus
}
#endif
S*********g
发帖数: 5298
8
来自主题: Programming版 - 弱问一个ifdef 和ifndef
#ifndef A
#ifndef B
#include "xxx.h"
#endif
#endif
g*********s
发帖数: 1782
9
来自主题: Programming版 - 搜狐一题,寻解法
n = 3, 4, 5的结果是多少?核对一下。
我的结果:
5 30 65
14 112 238
42 420 882
源码:
void print_legal_parentheses(int curr_pos, int pos_limit, int
left_count, std::vector& tag) {
#ifdef DEBUG
fprintf(stdout, "%d %d %d\n", curr_pos,
pos_limit, left_count);
#endif
if ( curr_pos == pos_limit ) {
for ( int i = 0; i < tag.size(); ++ i ) {
fprintf(stdout, "%c ", tag[i] == 0 ? '(' : ')');
}
fprintf(stdout, "\n");
ret... 阅读全帖
C***H
发帖数: 508
10
来自主题: Programming版 - 这个结果是啥,为什么呢?
某人今天问起,C语言中,如下定义:
#define A1 NULL
#define A2 NULL
#if (A1==NULL)
#undef A1
#define A1 t1
#elif (A2==NULL)
#undef A2
#define A2 t2
#endif
#if (A1==NULL)
#undef A1
#define A1 t1
#elif (A2==NULL)
#undef A2
#define A2 t2
#endif
编译完后,A1,A2分别是啥?
以为很直接,但实际上一试,发现结果和想象的不一样,没搞明白为什么,特来此一问
...
C***H
发帖数: 508
11
来自主题: Programming版 - 这个结果是啥,为什么呢?
guess not, changed to the following is the same:
#define A1 NULL
#define A2 NULL
#if (A1==NULL)
#undef A1
#define A1 t1
#endif
#if (A1==NULL)
#undef A1
#define A1 t1
#elif (A2==NULL)
#undef A2
#define A2 t2
#endif
c**********e
发帖数: 2007
12
来自主题: Programming版 - C++ Q 99-102 (转载)
【 以下文字转载自 JobHunting 讨论区 】
发信人: careerchange (Stupid), 信区: JobHunting
标 题: C++ Q 99-102
发信站: BBS 未名空间站 (Fri Oct 28 23:14:06 2011, 美东)
C++ Q 99: global and static
What type of linkage does global variables and functions preceded by
the storage class specifier static have?
a. Internal
b. Intern
c. External
d. Extern
Answer: a
C++ Q 100: directives
Any number of which of the following directives can appear between
the #if and #endif directives?
a. #elif
b. #endif
c. #else
d. #if
Answer: a
C++ Q101... 阅读全帖
c******s
发帖数: 270
13
要被继承的类(DllObject)定义在Project A, 用DLL导出. 而子类(MyClass)定义在
Project B.
在Project A中, 我定义了宏MYDLL_BUILD.
// Config_Project_A.h
#if !defined(MYDLL_BUILD)
# pragma comment(lib, "myDll.lib")
#endif
#if defined(MYDLL_BUILD)
# define MYDLL_API __declspec(dllexport)
#else
# define MYDLL_API __declspec(dllimport)
#endif
// DllObject.h
class MYDLL_API DllObject
{
public:
virtual ~DllObject() {}
protected:
DllObject() { m_count = 3; }
priv... 阅读全帖
d**d
发帖数: 389
14
来自主题: Programming版 - 关于C++中 extern "C"的问题。
比如我已经用C写好了几个独立的函数去处理一个xml文件,调用的库是现有的libxml2,
这个是标准的C library.
在parser.c中,
#include
#include
#include
void parser();
1. 如果我把这个文件放到我其他的C++程序中,还是parser.c,那么在调用G++编译的
时间,parser.c就要变成
#ifdef _cplusplus
extern "C"{
endif
void parser();
#ifdef _cplusplus
}
#endif
是这样吧?
2. 如果我重新生成一个parser.cpp文件:
#include
#include
#include
void parser();
这样的话,用g++来编译就没有问题了?
谢谢。
g***l
发帖数: 2753
15
来自主题: Programming版 - 请教一个C++中function pointer的问题。
老大的这个方法是可行的。可是又出现新的问题了。
我定义了如下接口:
template
dec_base* new_object()
{
return new T;
}
typedef dec_base* (*ObjectGenerator)();
static std::map generator_map;
template
void register_dec_handle(int tag_id)
{
generator_map.insert(make_pair(tag_id,new_object));
}
如果把以上代码跟 main() 代码放在一个main.cpp里面,编译链接都没有问题。但是如
果把以上代码放在另外一个单独的sample.cpp里面,在另外一个main.cpp中的main()调用
register_dec_handle()的时间,gcc就会报告
g++ main.cpp sample.cpp -o sample.exe
main.cpp: 在函数‘int main(... 阅读全帖
m***x
发帖数: 492
16
来自主题: Programming版 - how to export a class in a namespace in DLL?
Using VS2010, a class can be exported from DLL. the client can access it
without problem. when put it into a namespace, the client program has link
error: unsolved external objs...
Any idea? thanks
the dll header file is:
#pragma once
#ifndef ECONOMICS_API_DCL
#ifdef ECONOMICS_EXPORTS
#define ECONOMICS_API_DCL __declspec(dllexport)
#else
#define ECONOMICS_API_DCL __declspec(dllimport)
#endif
#endif
namespace Economics
{
class ECONOMICS_API_DCL InterestRate
{
publi... 阅读全帖
z****e
发帖数: 2024
17
Which of the following statements correctly describe the code below in C++?
#define language 437 //Line 1
#if language < 400
#undef language //Line 2
#else //Line 3
#define language 850 //Line 4
#ifdef language //Line 5
printf("%d", language); //Line 6
#endif
#endif
A. An error or warning will occur on Line 6 because a macro cannot be used
as part of a preprocessor directive.
B. An error or warning will occur on Line 2 because #undef is not a valid
preprocessor directive.
C. An error or warning ... 阅读全帖
G*****9
发帖数: 3225
18
来自主题: Programming版 - Urgent question: AIX, C++11, Shared Object
I am using AIX. I cannot generate .so file
Code:
#include
using namespace std;
#ifdef __cplusplus
extern "C" { // only need to export C interface if
// used by C++ source code
#endif
bool Myfunction( );
#ifdef __cplusplus
}
#endif
bool Myfunction( )
{
std::uniform_real_distribution U(0.0, 1.0);
std::mt19937_64 rnd;
rnd.seed(1);
return true;
}
command: g++ -std=c++0x -maix64 -c -Wall -ansi -g -fPIC test.cc
Error:
test.cc: In function 'bool Myfunctio... 阅读全帖
p*****w
发帖数: 429
19
来自主题: Programming版 - C问题,被64bit iPhone搞晕了
这样可以自己定义吗
?
#ifndef int32
#if sizeof(long)==4
#define int32 long
#endif
#if sizeof(int)==4
#endif
V*********r
发帖数: 666
20
来自主题: Programming版 - a python question

貌似是偶然跟别人讨论到的。前文“100以内”说得不准确,也没必要记,
设计思想就是常用的小整数缓存起来,避免频繁在堆上malloc造成不必要的开销。
刚翻了翻Python 3.4源码(注:Python 3里long已经和int统一了):
http://hg.python.org/cpython/file/3.4/Objects/longobject.c
#ifndef NSMALLPOSINTS
#define NSMALLPOSINTS 257
#endif
#ifndef NSMALLNEGINTS
#define NSMALLNEGINTS 5
#endif
/* Small integers are preallocated in this array so that they
can be shared.
The integers that are preallocated are those in the range
-NSMALLNEGINTS (inclusive) to NSMALLPOSINTS (not ... 阅读全帖
b**********h
发帖数: 419
21
来自主题: Programming版 - CIH源代码
究竟难在哪里?
; Win Cih Source Code
;I m not the dissembler of the code and really I don't know ;who is the
writer or dissembler . Compile or run this program ;at your own risk. Also I
m not giving any guarantee of running ;the program !!!.
;****************************************************************************
; * The Virus Program Information *
;****************************************************************************
; * *
; * Designer : CIH Source : TTIT of TATUNG in Taiwan... 阅读全帖
T********i
发帖数: 2416
22
来自主题: Programming版 - 请推荐C++开发环境
给你一个好了。thread和sleep。
disclaimer: 这个也是我抄的。
typedef void * (*qw_thread_func_t)(void *);
#if defined(_WIN32)
inline int qw_start_thread(qw_thread_func_t f, void *p) {
return (long)_beginthread((void(__cdecl *)(void *)) f, 0, p) == -1L ? -1
: 0;
}
#define qw_sleep(x) Sleep(x)
#else
inline int qw_start_thread(qw_thread_func_t func, void *param) {
pthread_t thread_id;
pthread_attr_t attr;
int result;
(void)pthread_attr_init(&attr);
(void)pthread_attr_setdetachstate(&attr, PTHRE... 阅读全帖
y**b
发帖数: 10166
23
来自主题: Programming版 - C++含有指针成员的类
我那个代码太庞大,没法贴。弄个小的,可以重现一楼的编译提示:
// A.h
#ifndef A_H
#define A_H
#include "B.h"
class A {
public:
void test(B *b) {}
private:
int a;
B b;
};
#endif
// B.h
#ifndef B_H
#define B_H
class A;
class B {
public:
~B() {delete a;}
private:
A *a;
};
#endif
// main.cpp
#include "A.h"
#include "B.h"
int main() {
A *pa = new A();
B *pb = new B();
delete pa;
delete pb;
return 0;
}
编译提示:
B.h:6:16: note: neither the destructor nor the class-specific operator
delete will be called, even if they... 阅读全帖
m*******m
发帖数: 182
24
Hmm, can you double check this?
In my source code main.c, I see it in the line 101-109
block.
...
101 #ifdef SVR4
102 #define SYSV /* SVR4 is (approx) superset
of SVR3 */
103 #define ATT
104 #define USE_SYSV_UTMP
105 /*#ifndef sgi*/ /* this doesn't really work,
-ygz */
106 #define USE_TERMIOS
107 /*#endif*/
108 #define HAS_UTMP_UT_HOST
109 #endif
...
m*******m
发帖数: 182
25
Hmm, can you double check this?
In my source code main.c, I see it in the line 101-109
block.
...
101 #ifdef SVR4
102 #define SYSV /* SVR4 is (approx) superset
of SVR3 */
103 #define ATT
104 #define USE_SYSV_UTMP
105 /*#ifndef sgi*/ /* this doesn't really work,
-ygz */
106 #define USE_TERMIOS
107 /*#endif*/
108 #define HAS_UTMP_UT_HOST
109 #endif
...
g*k
发帖数: 194
26
来自主题: Unix版 - 哪位大虾熟悉gnu的make?
给俺讲一下makelevel的作用和用法。
它是不是一个特殊的变量啊?
俺有一个很长的makefile文件,大致结构如下:
ifeq "$(makelevel)" "0"
....
endif
......
ifeq "$(makelevel)" "1"
....
endif
...
按道理说makelevel=0时是底层的编译过程,
但它为什么要写在makelevel=1这一层之前呢?
编译的流程到底是怎么样的?而且我在整个
makefile文件里并没有发现那里对makelevel
设置乐初值啊。
thx a lot.
g********d
发帖数: 89
27

Add a standard .login file in home dir
including the following
if (! $?ENVONLY) then
# Set the interrupt character to Ctrl-c and do clean backspacing.
if (-t 0) then
stty intr '^C' echoe
endif
# Set the TERM environment variable
eval `tset -s -Q`
endif
GB
发帖数: 256
28
来自主题: Unix版 - 提示我 too many ('s 怎么办?
sure.
in this csh script file.
some comment lines at the beginning,
then some 'set' and 'echo' stuff ,
then
if (! -d $roccSysInstallRootDir) then
echo "mkdir $roccSysInstallRootDir"
mkdir $roccSysInstallRootDir
endif
if (! -d $roccSysInstallRootDir) then
echo "You don't have right!\n"
exit
endif
blablablabla,,,,,,,,,,
d*z
发帖数: 150
29
来自主题: Science版 - Re: yes....1413
hehe , more than 600 lines:
#include
#include
#include
#include
#include
#include
#include
#ifdef _WIN32
typedef __int64 longlong;
using namespace std;
#else
typedef long long longlong;
#endif
#ifdef _DEBUG
#include
#define ASSERT(x) assert(x)
#else
#define ASSERT(x)
#endif
#define MAX_NUM 10
//enlarge CACHE_LIMIT so that some expression will be saved in memory. This
will speed the program,
//but then we could not print
E*V
发帖数: 17544
30
#ifndef justice
#define justice selfishness
#endif
x*******6
发帖数: 994
31
——本文面向具有小学文化程度即可的读者作扫盲用
先说点低科技
先拿最简单的菜刀来说,好一点的菜刀现在都造不出来。外面卖的好菜刀都是进口的
,什么德国刀、日本刀、英国刀、美国刀、法国刀,瑞士刀,反正发达国家都有,小菜
一碟。为什么z国那么多科学家就不能搞出几把好菜刀,满足一下广大人民的实际需要
呢?这可是千家万户天天要用到的阿,也应该不是什么难事吧,但实际就没有的。
至于男人的刮胡刀,理发店的剪刀,好一点的螺丝刀,好一点的螺丝,也一样,都是
进口的或外资厂生产的,z国根本生产不出来。国产的刮胡刀用了会刮破皮,理发剪会
拉头发,螺丝刀容易坏,螺丝容易滑丝、容易弯曲折断,技术根本不过关。
一把好菜刀、一把好螺丝刀都生产不出来,却宣称能造出航空母舰,这可能吗?航
空母舰上的钢板要能够起降飞机,能够经受住12级台风,能够经受住惊涛骇浪,那个强
度要求更高,可能吗?还有拦阻索,弹射机、发动机,都是代表机械领域的最高科技,
可能造出来吗?
外面好一点的自行车都是进口或外资厂生产,连好一点的自行车都造不出来。甚至连
厨房专用的抹布都搞不出来,超市里卖的抹布都是进口的或者外资厂生产... 阅读全帖
w*********g
发帖数: 30882
32
中国将建造中美高铁,引俄罗斯网友热评
China wants to build high−speed railway to US through Siberia and
Bering Strait
译工:discopy 发布日期:2014-06-23 浏览:0
译文简介
这个项目最雄心勃勃的部分显然包括要建造一条海底隧道以使穿越白令海峡成为可能。
长达200公里(125英里)的隧道将意味着令人望而生畏的工程挑战——这将是连接英国
和法国的海峡隧道长度的4倍——但是《中国日报》宣
译文来源
原文地址:http://rt.com/usa/157940-china-us-railway-siberia-bering/
正文翻译
-------------译者:青风梧桐-审核者:龙腾翻译总管------------
The idea of traveling between the United States and China without flying
might seem ridiculous to virtually everyone, but if Beijing ge... 阅读全帖
B*********h
发帖数: 246
33
来自主题: Military版 - 习近平怎么可能挺任志强
天真了吧。这段程序设计得这么明显,难道读不懂?
高举毛旗抓住政权
为剥削保驾护航
while 政权在手
放狗腿出来试探民意。
if 合适
then “顺应民意”,不再伪装,公开走资,瓜分公产。
break
if 民意反弹
then “处置”狗腿平民怨。
endif
endwhile
b*****n
发帖数: 2324
34
来自主题: Military版 - est