标签: redefinition

如何打印出tcl proc?

给出一个简单的tcl proc

proc foo {a b} {puts "$a $b"}
Run Code Online (Sandbox Code Playgroud)

我可以使用什么tcl命令打印出程序foo...这就是我想要proc 的文本回来...

例如:

% proc foo {a b} {puts "$a $b"}
% foo a b
  a b

% puts $foo
  can't read "foo": no such variable
Run Code Online (Sandbox Code Playgroud)

我怎么foo {a b} {puts "$a $b"}回来?

tcl redefinition proc-object

4
推荐指数
2
解决办法
5401
查看次数

在 C# 中编译包含重定义的架构

当读取包含<xs:redefine>标签的模式并尝试使用模式集编译它时,我收到此异常:

'SchemaLocation' must successfully resolve if <redefine>
contains any child other than <annotation>
Run Code Online (Sandbox Code Playgroud)

我尝试了许多不成功的解决方法,例如递归解析模式并将它们添加到编译之前的模式集中,甚至将它们添加为参考。架构仍然无法编译。尝试的示例(解析主 xsd,然后在调用此递归函数后尝试编译生成的“XmlSchemas”):

private void AddRecursive (XmlSchemas xsds, XmlSchema schema)
{
    foreach (XmlSchemaExternal inc in schema.Includes) {
        String schemaLocation = null;
        schemaLocation = inc.SchemaLocation;
        XmlSchema xsd;
        using (FileStream stream = new FileStream (schemaLocation, FileMode.Open, FileAccess.Read)) {
            xsd = XmlSchema.Read (stream, null);
            xsds.Add (xsd);
            xsds.AddReference (xsd);
        }
        AddRecursive (xsds, xsd);
    }
}
Run Code Online (Sandbox Code Playgroud)

处理此类模式的正确方法是什么?为什么模式编译器不能自己解析添加的模式?

c# xml schema include redefinition

4
推荐指数
1
解决办法
2919
查看次数

尝试构建XCode项目以进行发布时出现Typedef重新定义错误

我可以在Xcode(4.2)中构建我的项目以进行调试而不会出现问题,但是当我想构建它以进行发布(构建用于存档)时,我得到错误:"Typedef重新定义了不同的类型(unsigned int vs unsigned long)".

有问题的代码是:

#ifdef _LZMA_UINT32_IS_ULONG 
typedef long Int32; 
typedef unsigned long UInt32; 
#else 
typedef int Int32; 
typedef unsigned int UInt32; <--error on this line
#endif
Run Code Online (Sandbox Code Playgroud)

你可以看到整个文件:http: //read.pudn.com/downloads166/sourcecode/zip/758136/C/Types.h__.htm

以前的定义是在CoreServices框架中的MacTypes.h中.

我有与Debug和Release相同的预处理器宏,我正在使用Apple的LLVM编译器3.0.当我尝试构建用于分析的项目时,会发生同样的错误.

知道为什么会这样吗?

xcode typedef redefinition llvm-3.0

4
推荐指数
1
解决办法
1万
查看次数

多个包含错误,找不到解决方案

我最近一直在努力解决多个文件包含错误.我正在开发一个太空街机游戏并将我的类/对象划分为不同的.cpp文件,并确保一切仍然可以正常工作我已经构建了以下头文件:

#ifndef SPACEGAME_H_INCLUDED
#define SPACEGAME_H_INCLUDED
//Some Main constants
#define PI 3.14159265


//Standard includes
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <math.h>
#include <string.h>
#include <iostream>
#include <vector>
using namespace std;

//SDL headers
#include "SDL.h"
#include "SDL_opengl.h"
#include "SDL_mixer.h"
#include "SDL_image.h"

//Classes and project files
#include "Player.cpp"
#include "planet.cpp"
#include "Destructable.cpp"
#include "PowerUp.cpp"
#include "PowerUp_Speed.cpp"

#endif // SPACEGAME_H_INCLUDED
Run Code Online (Sandbox Code Playgroud)

在我的每个文件的顶部,我包括(仅)此头文件,其中包含所有.cpp文件和标准包含.

但是,我有一个Player/Ship类,它给了我' 重新定义Ship类 '类型的错误.我最终通过在类定义文件中包含预处理器#ifndef和#define命令找到了一种解决方法:

#ifndef PLAYER_H
#define PLAYER_H
/** Player class that controls the flying object used for the space game …
Run Code Online (Sandbox Code Playgroud)

c++ file redefinition inclusion

4
推荐指数
1
解决办法
634
查看次数

为什么非常量静态成员有多个定义?

C++强制程序员在类外部定义一个非常量静态成员,我不断看到的原因是如果静态成员是在类中定义的,这将导致静态成员的多个定义.我知道有一个静态成员的多个定义是坏的,但我不明白这些多个定义甚至会来自何处.初始化的非常量静态成员不应该只进入数据部分并且这是唯一的定义吗?

struct Student {

   static int x = 4; // Why would this result in multiple definitions?

};
Run Code Online (Sandbox Code Playgroud)

另外,我在其他stackoverflow文章中读到,const静态成员只是在使用它的地方简单地内联到代码中: 为什么我不能在类中有一个非整数的静态const成员? 这是由预处理器和所有其他指令处理的吗?(如果需要,我会在另一篇文章中提出这个问题,但我不确定它是否值得单独发帖).

c++ static const member redefinition

4
推荐指数
1
解决办法
159
查看次数

typedef 重定义在 C11 中如何工作?

我读到在 C11 中 typedef 重新定义是允许的,只要定义相同。然而下面的代码

typedef struct {
    int x;
} a_t;

typedef struct {
    int x;
} a_t;

int main(int argc, char* argv[]) {
    a_t a;
    return a.x + argc;
}
Run Code Online (Sandbox Code Playgroud)

当使用 C11 标志编译时,出现重新定义错误:

% clang -std=c11 -o x x.c
x.c:7:3: error: typedef redefinition with different types ('struct a_t' vs 'struct a_t')
} a_t;
  ^
x.c:3:3: note: previous definition is here
} a_t;
  ^
1 error generated.

Run Code Online (Sandbox Code Playgroud)

有趣的是,如果 typedef 只是一个原始类型(即“typedef int a_t;”),那么即使没有“-std=c11”标志,重新定义也不会抛出错误。

为什么不能重新定义具有结构的类型?

这是一个来自第三方标头的定义的问题。

c struct typedef definition redefinition

4
推荐指数
1
解决办法
1104
查看次数

LNK2005:"已定义错误

我试图从分离的.cpp文件中使用全局变量.我有一个init.h文件:

//init.h
#ifndef init
#define init
int a = 3;
#endif
Run Code Online (Sandbox Code Playgroud)

我有一个init.cpp文件: //init.cpp #include init.h

最后我的main.cpp文件是:

//main.cpp
#include "init.h"
int main(void)
{
    while(1)
    {
    }
}
Run Code Online (Sandbox Code Playgroud)

在此之后,我收到错误:

1>init.obj : error LNK2005: "int a" (?a@@3HA) already defined in main.obj
1> ..deneme.exe : fatal error LNK1169: one or more multiply defined symbols found
Run Code Online (Sandbox Code Playgroud)

为什么我的#infdef控件无法解决这个问题?我也试过使用,#pragma once但我得到了同样的错误.我的代码出了什么问题?

c++ linker redefinition

3
推荐指数
1
解决办法
2133
查看次数

静态方法重新定义规则

我知道这是一个非常讨厌的话题,但我需要澄清一些事情,所以请耐心等待一分钟.

静态方法与任何其他方法一样继承,并遵循相同的关于访问修饰符的继承规则(不继承私有方法等)

静态方法没有被覆盖,它们被重新定义.如果一个子类定义了一个与超类中具有相同签名的静态方法,则称它是遮蔽或隐藏超类的版本而不是覆盖它,因为它们不像实例方法那样是多态的.

重新定义的静态方法似乎仍然遵循一些(如果不是全部)超越规则.

首先,重新定义的静态方法不能比超类的静态方法更多地限制访问.为什么??

其次,返回类型在超类和子类的方法中也必须兼容.例如:

class Test2 {
    static void show() {
        System.out.println("Test2 static show");
    }
}

public class StaticTest extends Test2 {
    static StaticTest show() {
        System.out.println("StaticTest static show");
        return new StaticTest();
    }

    public static void main(String[] args) {
    }

}
Run Code Online (Sandbox Code Playgroud)

在eclipse中它显示了一个错误: The return type is incompatible with Test2.show() 为什么?

第三,是否有遵循了重新定义静态方法它们相同压倒一切的,什么是对这些规则的原因,规则的任何其他规则?

Thanx提前!!

java static-methods overriding redefinition

3
推荐指数
1
解决办法
1112
查看次数

C - Xcode中的重定义错误

我的c头文件在Xcode中有以下错误消息

Redefinition of 'entry'
Run Code Online (Sandbox Code Playgroud)

但是当我gcc在命令行中使用它编译它时,它工作得很好.你们中的任何人都可以解释原因吗?

这是snapshot.h:

#ifndef SNAPSHOT_H
#define SNAPSHOT_H

#define MAX_KEY_LENGTH 16
#define MAX_LINE_LENGTH 1024

typedef struct value value;
typedef struct entry entry;
typedef struct snapshot snapshot;

struct value {
    value* prev;
    value* next;
    int value;
};

// the line below is where the redefinition error appears
struct entry {
    entry* prev;
    entry* next;
    value* values;
    char key[MAX_KEY_LENGTH];
};

struct snapshot {
    snapshot* prev;
    snapshot* next;
    entry* entries;
    int id;
};

#endif
Run Code Online (Sandbox Code Playgroud)

这是snapshot.c:

#include <stdio.h> …
Run Code Online (Sandbox Code Playgroud)

c xcode header-files redefinition

3
推荐指数
1
解决办法
2074
查看次数

函数重定义:const 参数

1. 在全局范围内,这给出error: redefinition of 'f'

#include <iostream> 
using namespace std; 
  
void f(int x) { cout << "f" << endl; }
void f(const int x) { cout << "f (const)" << endl; } // error: redefinition of 'f'
int main() { } 
Run Code Online (Sandbox Code Playgroud)

2. 定义两个复制构造函数(一个带const,另一个不带)编译

#include <iostream> 
using namespace std; 
  
class Foo { 
public: 
    Foo(const Foo&) { cout << "copy (const)" << endl; }
    Foo(Foo&) { cout << "copy" << endl; }
}; 

int main() { } 
Run Code Online (Sandbox Code Playgroud)

问题

  1. 为什么 …

c++ copy-constructor redefinition

3
推荐指数
1
解决办法
791
查看次数