“token”之前的“expected”:“,',',';','}'或'__attribute__'在Struct成员函数中 [英] "expected ':', ',', ';', '}' or '__attribute__' before '{' token" in Struct member function

查看:173
本文介绍了“token”之前的“expected”:“,',',';','}'或'__attribute__'在Struct成员函数中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让我的prof的overengineered C ++代码编译。这是我有的代码:

I'm trying to get my prof's overengineered C++ code to compile. This is the code I have:

/**
 * Vector class.
 * Common mathematical operations on vectors in R3.
 *
 * Written by Robert Osada, March 1999.
 **/
#ifndef __VECTOR_H__
#define __VECTOR_H__

/**
 * Vector3
 **/
struct Vector3f
{
  // coordinates
  float x, y, z;

  // norm
  float      normSquared () { return x*x+y*y+z*z; }
  double norm        () { return sqrt(normSquared()); }

  // boolean operators
  bool operator == (const Vector3f& v) const { return x==v.x && y==v.y && z==v.z; }
  bool operator != (const Vector3f& v) const { return x!=v.x || y!=v.y || z!=v.z; }

  // operators
  Vector3f  operator +  (const Vector3f &v) const { return Vector3f(x+v.x, y+v.y, z+v.z); }
  Vector3f& operator += (const Vector3f &v)       { x+=v.x; y+=v.y; z+=v.z; return *this; }
  Vector3f  operator -  () const                 { return Vector3f(-x, -y, -z); }
  Vector3f  operator -  (const Vector3f &v) const { return Vector3f(x-v.x, y-v.y, z-v.z); }
  Vector3f& operator -= (const Vector3f &v)       { x-=v.x; y-=v.y; z-=v.z; return *this; }
  Vector3f  operator *  (float s) const              { return Vector3f(x*s, y*s, z*s); }
  Vector3f& operator *= (float s)                { x*=s; y*=s; z*=s; return *this; }
  Vector3f  operator /  (float s) const          { assert(s); return (*this)* (1/s); }
  Vector3f& operator /= (float s)                { assert(s); return (*this)*=(1/s); }

 // create a vector
 Vector3f (float x_=0, float y_=0, float z_=0) : x(x_), y(y_), z(z_) {};

 // set coordinates
 void set (float x_, float y_, float z_) { x=x_; y=y_; z=z_; }
};

inline float Dot (const Vector3f& l, const Vector3f r)
{
  return l.x*r.x + l.y*r.y + l.z*r.z;
}

// cross product
inline Vector3f Cross (const Vector3f& l, const Vector3f& r)
{
  return Vector3f(
    l.y*r.z - l.z*r.y,
    l.z*r.x - l.x*r.z,
    l.x*r.y - l.y*r.x );
}

#include "Misc.h"
/*
inline Vector3f Min (const Vector3f &l, const Vector3f &r)
{
  return Vector3f(Min(l.x,r.x), Min(l.y,r.y), Min(l.z,r.z));
}

inline Vector3f Max (const Vector3f &l, const Vector3f &r)
{
  return Vector3f(Max(l.x,r.x), Max(l.y,r.y), Max(l.z,r.z));
}
*/
#endif

在定义normSquared()的行上获取错误。它似乎给出一个错误,无论哪个方法首先在结构中。有任何建议吗?

and I'm getting the error on the line which defines normSquared(). It seems to give an error regardless of which method comes first in the struct. Does any have any suggestions?

推荐答案

您是否试图用C编译器编译?如果你尝试用C编译器编译你的C ++代码,我想你会得到这些类型的消息。

Are you trying to compile with a C compiler maybe? If you try to compile your C++ code with a C only compiler I think you would get those type of messages.

这篇关于“token”之前的“expected”:“,',',';','}'或'__attribute__'在Struct成员函数中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆