2016-04-14 16 views
-1

VS2015'te derlemek için g ++ ile derlenebilir olan kodları almaya çalışmak. Çok fazla şansla SO & Google'a baktım, ancak cmath, MSDN'de belgelendi. Sanırım gerçekten açık veya basit bir şey kaçırıyorum.Visual Studio 2015'te cmath Kullanırken 200 Hata Yaklaşık

cmath ben derleme sırasında alıyorum hataların çoğu hataların bir sürü atıyor, ve yarım biçimindedir:

the global scope has no "<function>" 

diğerleri şeklindedir

'<function>': redefinition; different exception specification 

'<function>': identifier not found 

'<function>': is not a member of "global namespace" 

ı don Bu hataların neden atıldığını anlayamıyorum, ancak, eğer math.h kullanırsam, derleme hatalarımın çoğu gider (bazıları da diğer standart lib'lerde de dahil olmak üzere).

Düzenleme: İstendiği gibi, kod. Ben sqrt & pow fonksiyonlarını kullanıyorum:

#include "vector.h" 
#include <cmath> 

using namespace vectormath; 

vector::vector() 
{ 
    this->_x = 0; 
    this->_y = 0; 
    this->_z = 0; 
    this->_length = 0; 
} 
vector::vector(float x, float y, float z) 
{ 
    this->_x = x; 
    this->_y = y; 
    this->_z = z; 
    this->_length = sqrt(pow(_x, 2) + pow(_y, 2) + pow(_z, 2)); 
} 

vector * vectormath::crossproduct(vector * a, vector * b) 
{ 
    vector * result = new vector(); 

    result->_x = a->_y * b->_z - a->_z * b->_y; 
    result->_y = a->_z * b->_x - a->_x * b->_z; 
    result->_z = a->_x * b->_y - a->_y * b->_x; 

    return result; 
} 

point::point() 
{ 
    this->_x = 0.0; 
    this->_y = 0.0; 
    this->_z = 0.0; 
} 

point::point(float x, float y, float z) 
{ 
    this->_x = x; 
    this->_y = y; 
    this->_z = z; 
} 

float vectormath::dotproduct(vector a, vector b) 
{ 
    return a._x * b._x + a._y * b._y + a._z * b._z; 
} 

vector * vectormath::add(point * a, vector * b) 
{ 
    vector * c = new vector(); 

    c->_x = a->_x + b->_x; 
    c->_y = a->_y + b->_y; 
    c->_z = a->_z + b->_z; 

    return c; 
} 

Edit: ve vector.h

#include <math.h> 

ve

#include <cmath> 

arasındaki fark olmasıdır

namespace vectormath 
{ 
    struct vector 
    { 
     float _x; 
     float _y; 
     float _z; 
     float _length; 

     vector(); 
     vector(float x, float y, float z); 
    }; 

    struct point 
    { 
     float _x; 
     float _y; 
     float _z; 

     point(); 
     point(float x, float y, float z); 
    }; 
    vector * crossproduct(vector*, vector*); 
    float dotproduct(vector a, vector b); 
    vector * add(point * a, vector * b); 
} 
+2

'cmath' kullanan kodunuz nerede? [Mcve] var mı? – Niall

+0

Ayrıca, cmath kullanmayı beyanınızı gösterebilir misiniz? Sadece durumda :) –

+0

Hatayı http://webcompiler.cloudapp.net (VS derleyici) üzerinde yeniden oluşturamıyorum. Üstbilgisinde koruma yok ya da '#pragma bir kez 'yok ... birkaç cpp dosyasına eklenmişse sorunlara neden olabilir. – Niall

cevap

3

eski şeyler koyar sqrt ve küresel isim alanına pow gibi (yani, sadece sqrt veya pow diyerek onlara bakın) ve ikincisi ad std içine koyar (yani sen std::sqrt veya std::pow diyerek onlara bakın).

Eğer std:: ile onları her zaman önüne zorunda, açıkça genel ad alanında bireysel olanları koyabilirsiniz değil isterseniz: (bu tavsiye edilmez olsa)

using std::sqrt; 

ya indirebiliriz böyle std tamamı:

using namespace std; 

bununla bela std isimler bir çok ve muhtemelen gerçekten hepsini istemiyoruz olmasıdır.