考虑一个类:
class loc{
int x;
int y;
public:
loc();
loc(int x,int y);
loc(const loc& l);//Copy Constructor
loc operator + (const loc& l);
loc operator - (const loc& l);
loc& operator = (const loc& l);//Assignment Operator
const loc& operator ++ ();
friend ostream& operator << (ostream& os,const loc& l);
friend istream& operator >> (istream& is,loc& l);
~loc();
};
Run Code Online (Sandbox Code Playgroud)
当我调用Assignment运算符时:
int main()
{
loc Ob;
cout << "########\n\n";
cin >> Ob;
cout << "Ob : " << Ob;
cout << "\n\n########\n\n";
loc …Run Code Online (Sandbox Code Playgroud) 对于下面的代码,我如何char[][]作为char**参数传递?
#include <stdio.h>
#include <string.h>
void fn(int argc,char** argv)
{
int i=0;
printf("argc : %d\n",argc);
for(i=0;i<argc;i++)
printf("%s\n",argv[i]);
}
int main()
{
char var3[3][10]={"arg1","argument2","arg3"};
char var4[4][10]={"One","Two","Three","Four"};
fn(3,&var3);
fn(4,&var4);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
得到以下错误:
$ gcc -Wall anyNumberOfParameters.c -o anyNumberOfParameters.exe
anyNumberOfParameters.c: In function ‘main’:
anyNumberOfParameters.c:18:1: warning: passing argument 2 of ‘fn’ from incompatible pointer type [enabled by default]
fn(3,&var3);
^
anyNumberOfParameters.c:5:6: note: expected ‘char **’ but argument is of type ‘char (*)[3][10]’
void fn(int argc,char** argv)
^
anyNumberOfParameters.c:19:1: warning: …Run Code Online (Sandbox Code Playgroud) 我想只在_DEBUG定义时打印信息
#define DEBUG(y) y == true ? #define _DEBUG true : #define _DEBUG false
#ifdef _DEBUG
#define Print(s) printf(s);
#endif
Run Code Online (Sandbox Code Playgroud)
得到错误:
error: '#' is not followed by a macro parameter
Run Code Online (Sandbox Code Playgroud)
有任何建议如何使用预处理器指令实现这一目标?
我打算从我的主要使用它:
DEBUG(true);
Print("Inside main in debug mode");
Run Code Online (Sandbox Code Playgroud) 考虑以下代码:
BST.h
#ifndef BST_H
#define BST_H
#include <iostream>
typedef char Key;
typedef int Value;
#define NULL 0
class BST{
private:
class Node{
Key key;
Value value;
Node* left;
Node* right;
int N;
public:
Node(Key key='A',Value value=NULL,Node* left=NULL,Node* right=NULL,int N=0):
key(key),value(value),left(left),right(right),N(N)
{
std::cout << "(Node created) Key: " << key << " Value : " << value << std::endl;
N++;
}
int getN()
{
return N;
}
bool operator==(Node& node)
{
if (this->key == node.key && this->value == node.value && this->left …Run Code Online (Sandbox Code Playgroud)