我刚刚在一些旧代码中找到了这个,我不确定它的含义.
Dim sTemp As String * 1
Run Code Online (Sandbox Code Playgroud)
最后的*1是什么?
谢谢!
据我所知,在C++中,只要在所有这些声明中具有相同的类型,就可以多次声明相同的名称.要声明类型的对象int,但不定义它,extern则使用关键字.所以以下内容应该是正确的并且编译没有错误:
extern int x;
extern int x; // OK, still declares the same object with the same type.
int x = 5; // Definition (with initialization) and declaration in the same
// time, because every definition is also a declaration.
Run Code Online (Sandbox Code Playgroud)
但是一旦我将它移到函数内部,编译器(GCC 4.3.4)就会抱怨我正在重新声明x并且它是非法的.错误消息如下:
test.cc:9: error: declaration of 'int x'
test.cc:8: error: conflicts with previous declaration 'int x'
Run Code Online (Sandbox Code Playgroud)
int x = 5;第9行在哪里,extern int x在第8行.
我的问题是:
如果多个声明不应该是错误,那么为什么在这种特殊情况下它是一个错误?
我有代码:
class Point3D{
protected:
float x;
float y;
float z;
public:
Point3D(){x=0; y=0; z=0;}
Point3D(const Point3D & point){x = point.x; y = point.y; z = point.z;}
Point3D(float _x,float _y,float _z){x = _x; y = _y; z = _z;}
}
class Vector3D{
protected:
Point3D start;
Point3D end;
public:
...
Point3D getSizes(){
return Point3D(end-start);
}
}
Run Code Online (Sandbox Code Playgroud)
我想为Point3D创建和运算符+,它将采用向量:
Point3D & operator+(const Vector3D &vector){
Point3D temp;
temp.x = x + vector.getSizes().x;
temp.y = y + vector.getSizes().y;
temp.z = z + vector.getSizes().z;
return temp;
} …Run Code Online (Sandbox Code Playgroud) 我在这里看到这个问题: 如何使用extern在源文件之间共享变量? 按照手册.但我仍然得到链接器错误...很想得到一些帮助和解释为什么它发生..
我有2个.c文件和一个头文件:
------ check.h ----
#ifndef check
#define check
extern int num;
#endif
Run Code Online (Sandbox Code Playgroud)
---- ---- check.c
#include "check.h"
#include <stdio.h>
int func(int x, int y)
{
int z = x+y;
return z;
}
void printnum()
{
num++;
printf("%d",num);
}
Run Code Online (Sandbox Code Playgroud)
---- ---- ynnynyny.c
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <string.h>
#include "check.h"
#include "check.c"
int num = 10;
int main()
{
printf("num before is : %d\n",num);
printnum();
printf("num now is : %d",num);
getchar();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我一直收到这些错误:
1> …Run Code Online (Sandbox Code Playgroud) 它是这样的,第四个,第五个:
void * copyFile( void * arg )
{
struct dirent *ent = (dirent *)arg;
}
Run Code Online (Sandbox Code Playgroud)
GCC告诉我'dirent' undeclared (first use in this function).
在你问之前,这个论点是void *因为它被传递给了一个pthread,而这正是我被教导的方式,而且因为这是我第一次线程化(它很痛),我只是在做我被告知的事情因为我在这里的理解充其量是微弱的.
我有三个文件:myh.h; my.cpp; use.cpp.以下是文件的内容:
myh.h
extern int foo;
void print_foo();
void print(int);
Run Code Online (Sandbox Code Playgroud)
my.cpp
#include "myh.h"
#include <iostream>
void print_foo()
{
std::cout<<foo<<std::endl;
}
void print(int i)
{
std::cout<<i<<std::endl;
}
Run Code Online (Sandbox Code Playgroud)
use.cpp
#include "myh.h"
int main()
{
foo=7;
print_foo();
print(99);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
GCC发出以下错误:
my.o:my.cpp:(.text+0x7): undefined reference to `foo'
use.o:use.cpp:(.text+0x10): undefined reference to `foo'
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
我使用-c命令编译文件,它不会给出错误.我使用以下命令进行链接:
g++ -o final my.o use.o
Run Code Online (Sandbox Code Playgroud)
这里有什么问题,我读了类似问题的其他主题,这里的情况很奇怪.....
好奇的是,这是Stroustrup的"使用C++编程原则"一书中的练习练习
编辑:我做了像dasblinkenlight说的那样,并且在use.cpp中我在foo前添加了一个int(所以现在定义了foo),但我仍然得到这个错误:
my.o:my.cpp:(.text+0x7): undefined reference to `foo'
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
哪个告诉我它在my.cpp中也没有定义呢?如果我必须在任何地方定义它在头文件中包含它的重点是什么,或者如何更恰当地接近它?
请注意以下内容......
//pattern 1
public class Cheesesteak
{
public string bread {get; private set}
public string cheese {get; private set}
public Cheesesteak()
{
bread = "Amoroso";
cheese = "Cheez Whiz";
}
}
//pattern 2
public class Cheesesteak
{
public string bread
{
get {return bread;}
set
{
bread = "Amoroso";
}
}
public string cheese
{
get {return cheese;}
set
{
cheese = "Cheez Whiz";
}
}
public Cheesesteak() {}
}
Run Code Online (Sandbox Code Playgroud)
这是一个好奇心的问题.是否有任何优势或特殊原因可以在"set"的定义中设置变量而不是在构造函数中声明它们?我最初的猜测是模式1更短,但在编译期间效率较低.
这是一个Perl n00b问题,但我没有找到一个清晰易懂的在线回答.
我有这个代码:
1.sub remCH();
2.#some stuff
3.$line = remCH($line);
4.
5.sub remCH() {
6.$rem = shift;
7.$rem = chomp($rem);
8.return ($rem);
9.}
Run Code Online (Sandbox Code Playgroud)
执行此代码时总是会出现以下错误(第24行将在上面的代码中为第3行):
Too many arguments for main::rem_CRLF at ./make_csv.pl line 24, near "$line)"
Run Code Online (Sandbox Code Playgroud)
根据我的理解,这是因为函数设置为返回一些东西但是当我声明它时,它被声明为"void".
我如何声明如下函数???
sub remCH(string/integer);
Run Code Online (Sandbox Code Playgroud) 我想在PHPMYADMIN中使用声明运行查询.
这是我的查询代码
declare @shopdomain varchar(30);
SET @shopdomain = 'newdomain.com';
UPDATE trans SET tval=REPLACE(name,'olddomain.de', @shopdomain ) WHERE name LIKE 'olddomain.de';
UPDATE settings SET tval=REPLACE(name,'olddomain.de', @shopdomain ) WHERE name LIKE 'olddomain.de';
UPDATE...
Run Code Online (Sandbox Code Playgroud)
PHPMYADMIN显示此错误
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'declare @shopdomain varchar(30)' at line 1
Run Code Online (Sandbox Code Playgroud)
我做错了什么?
传递给function1和function2的区别是什么?
struct Node
{
int data;
struct Node *next;
};
void function1(struct Node *start)
{
// ...
}
void function2(Node *start)
{
// ...
}
Run Code Online (Sandbox Code Playgroud)