我写了一个c ++程序fllow(3.43.cpp):
#include <iostream>
using std::cout;
using std::endl;
void version_1(int **arr) {
for (const int (&p)[4] : arr) {
for (int q : p) {
cout << q << " ";
}
cout << endl;
}
}
int main() {
int arr[3][4] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
version_1(arr);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
然后我使用:编译它gcc my.cpp -std=c++11
,有一个我无法处理的错误.信息:
3.43.cpp:6:30: error: no matching function for call to ‘begin(int**&)’
for (const int (&p)[4] : arr) { …
Run Code Online (Sandbox Code Playgroud) 这是"C编程语言"一书中的程序.
有一个错误:'strdup'的冲突类型!当遇到函数'strdup'时.但是如果你将'strdup'改为其他名称,例如'strdu',错误就会消失.
我不知道为什么?顺便说一下,我使用code :: blocks作为我的IDE.
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#define MAXWORD 100
struct tnode {
char *word;
int count;
struct tnode *left;
struct tnode *right;
};
struct tnode *addtree(struct tnode *, char *);
struct tnode *talloc(void);
void treeprint(struct tnode *);
int getword(char *, int);
char *strdup(char *);
/* word frequency count */
int main()
{
struct tnode *root;
char word[MAXWORD];
root = NULL;
while (getword(word, MAXWORD) != EOF)
if (isalpha(word[0]))
root = addtree(root, word);
treeprint(root); …
Run Code Online (Sandbox Code Playgroud) Sales_data.h
#ifndef SALES_DATA_H
#define SALES_DATA_H
#include <string>
class Sales_data {
friend std::istream &read(std::istream &in, Sales_data &data);
friend std::ostream &print(std::ostream &out, const Sales_data &data);
public:
Sales_data() = default;
//Sales_data(std::string _bookNo="", unsigned _units_sold = 0, double _revenue = 0)
//:bookNo(_bookNo), units_sold(_units_sold), revenue(_revenue) {}
std::string isbn() { return bookNo; }
Sales_data& combine(const Sales_data&);
double avg_price() const;
private:
std::string bookNo;
unsigned units_sold = 0;
double revenue = 0;
};
Sales_data &Sales_data::combine(const Sales_data& data) {
units_sold += data.units_sold;
revenue += data.revenue;
return *this;
}
std::istream …
Run Code Online (Sandbox Code Playgroud)