小编Nic*_*sky的帖子

奇怪的“未定义符号”错误?

我正在学习C++,我得到了这个错误:

Undefined symbols:
  "_main", referenced from:
      start in crt1.10.6.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)

我的代码是这样的

  #include <stdlib.h>
  #include <iostream>

  class Fraction {
      private:
          int num, den;
      public:
          void set(int n, int d) {num=n; den=d; normalize();}
          int get_num(){return num;}
          int get_den(){return den;}
      private:
          void normalize();

          int gcf(int a, int b);
          int lcm(int a, int b);
  };

  void Fraction::normalize() {
      if (den == 0 || num == 0) {
          num = 0;
          den = 1;
      }

      if …
Run Code Online (Sandbox Code Playgroud)

c++

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

C++程序报告未找到符号错误

嗨,我一直在写(和学习)C++,我在程序中正确地编写了所有代码(或者我认为).我收到此错误:

 "rands(int)", referenced from:
      _main in ccgc4zY9.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)

我的代码是这样的:

#include<iostream>
#include<stdlib.h>
#include<time.h>
#include<cmath>

using namespace std;

int rands(int n);
int hits[10];

int main ()  {
    int n;
    int i;
    int r;
    srand(time(NULL));

    cout<<"enter a number of trials to run"<<endl;
    cin>>n;

    for (i=1; i<=n; i++) {
        r=rands(10);
        hits[r]++;
    }

    for (i=0; i<10; i++) {
        cout<<i<<":"<<hits[i]<<"<Accuracy";
        cout<<static_cast<double>(hits[i])/(n/10)<<endl;
    }

    return 0;
}

int randns(int n) {
    return rand()%n;
}
Run Code Online (Sandbox Code Playgroud)

任何帮助表示赞赏!

c++

0
推荐指数
1
解决办法
104
查看次数

架构x86_64的未定义符号

好的我正在学习c ++而且我收到了这个错误

Undefined symbols for architecture x86_64:
  "Point::set(int, int)", referenced from:
      Point::Point(int, int)in ccHkya9E.o
  "Point::add(Point const&)", referenced from:
      Point::operator+(Point const&)in ccHkya9E.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)

这是我的代码

#include<iostream>

 using namespace std;

 class Point {
 private:
   int x, y;
 public:
   Point() {}
   Point(int new_x, int new_y) {set(new_x, new_y);}
   Point (const Point & src) {set(src.x, src.y);}

 //Operations
   Point add (const Point &pt);
   Point sub (const Point &pt);
   Point operator+(const Point &pt) {return add(pt);}
   Point …
Run Code Online (Sandbox Code Playgroud)

c++

0
推荐指数
1
解决办法
5104
查看次数

这些错误是什么?我怎么修理它们?

我正在学习c ++,我正在写一个卡片经销商计划.当我编译我的代码时,我得到这些错误:

dealer3.cpp:12: error: expected initializer before ‘int’
dealer3.cpp:33: error: expected constructor, destructor, or type conversion before ‘=’ token
dealer3.cpp:34: error: expected constructor, destructor, or type conversion before ‘=’ token
dealer3.cpp:35: error: expected constructor, destructor, or type conversion before ‘=’ token
dealer3.cpp:36: error: expected constructor, destructor, or type conversion before ‘=’ token
dealer3.cpp:37: error: expected constructor, destructor, or type conversion before ‘<<’ token
dealer3.cpp:38: error: expected declaration before ‘}’ token
Run Code Online (Sandbox Code Playgroud)

这是我的代码

#include<iostream>
#include<time.h>
#include<stdlib.h>
#include<cmath>

using namespace std;

int randn(int …
Run Code Online (Sandbox Code Playgroud)

c++

-2
推荐指数
1
解决办法
1053
查看次数

标签 统计

c++ ×4