'sqrt' : ambiguous call to overloaded function ..\assimp\vector3.inl - c++

Error
error C2668: 'sqrt' : ambiguous call to overloaded function c:\program files\assimp\include\assimp\vector3.inl
occures when I include 'scene.h' in main cpp file:
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
GLFWwindow* window;
#include <glm/glm.hpp>
#include <glm/gtx/transform.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <assimp/Importer.hpp>
#include <assimp/scene.h>
#include <assimp/postprocess.h>
#define MESH_FILE "cube.obj"
using namespace glm;
#include "common/shader.hpp"
#include "common/controls.hpp"
I can't get what does it conflict with?

You have a namespace using-directive in your .cpp file:
using namespace glm;
This means that everything that is in the glm namespace becomes part of the "global" namespace; so you are polluting the global namespace.
So, there might be some form of conflict between the standard C sqrt() function (which lives in the global namespace) and your glm::sqrt(), which is "promoted" to a global sqrt.
You may want to remove the aforementioned namespace using-directive (and just add the glm:: namespace prefix when you want to reference classes and functions in that namespace).

Related

Trouble with including external directories in C++ with ViconDataStreamSDK

#include <iostream>
#include <cassert>
#include <vector>
#include <algorithm>
#include <functional>
#include <limits>
#include <math.h>
#include "DataStreamClient.h" //[x]
#include "stdafx.h"
using namespace ViconDataStreamSDK::CPP;
{ ...
This is the start of my file that uses the header file ViconDatastreamSDK.h but in every instance that a class from the file is called Visual Studio gives the error:
'ViconDataStreamSDK': is not a class or namespace name
The solution explorer shows that the file is included in the external directories.
How do I get VisualStudio to recognize these classes?

Error LNK2005: function already defined in MyForm.obj

I'm trying to make a windows form application in Visual Studio C++, but I get this errors after compiling, for each function:
error LNK2005: function already defined in MyForm.obj
These are my files:
Source.cpp
#pragma once
#include "MyForm.h"
using namespace System;
using namespace System::Windows::Forms;
[STAThread]//leave this as is
void main() {
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
Application::Run(gcnew Project1::MyForm);
}
MyForm.h
#pragma once
#include <iostream>
#include <string>
#include "Header.h"
namespace Project1 {
//codes of te form
}
Header.h
#pragma once
#include <iostream>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
using namespace std;
int n, m;
int size1, size2;
//My functions here
So how can I fix errors?
If you declare and implement a function in a header file (Header.h) and if this file gets included twice, then you'll most likely will get a function already defined error at some point.
This can be fixed by either:
Moving function implementation to a source (cpp) file and only keep it's declaration in the header (h) file
Make the function inline (if it is acceptable), that will remove the error

‘hash’ is already declared in this scope using tr1::hash;

I am trying to compile C++ code shown below but I got an error saying,
In file included from src/LM.h:3:0,
from src/LM.cpp:1:
src/common.h:30:13: error: ‘hash’ is already declared in this scope
using tr1::hash;
This is the command I used to compile the files below.
g++ -std=c++11 -Wall src/Foo.cpp
Foo.cpp
#include "Foo.h"
...
Foo.h
#ifndef FOO_H
#define FOO_H
#include "common.h"
//more code here
#endif
common.h
#ifndef _COMMON_H_
#define _COMMON_H_
#include <iostream>
#include <fstream>
#include <cmath>
#include <cassert>
#include <cstdlib>
#include <utility>
#include <vector>
#include <string>
#include <array>
#include <algorithm>
#include <set>
#include <tr1/unordered_map>
#include <tr1/functional>
namespace std {
using tr1::unordered_map;
using tr1::hash;
} // namespace std
using namespace std;
//more code here
#endif
I want the source code to use std::tr1::unordered_map and std::tr1::hash rather than std::unordered_map and std::hash(Actually I am making some modifications to distributed files which does uses std::tr1::unordered_map and std::tr1::hash).
What is possibly wrong with my codes?
UPD:
https://github.com/clab/fast_align/blob/master/src/port.h seems to do the same thing as mine. However, this compiles without any problem... Have any idea?
There is already std::hash in C++11. You cannot redefine it. You can use another name for tr1::hash.
Probably the best idea (if you really want to use std::tr1::hash/std::tr1::unordered_map instead of C++11 structures) is to write your own namespace in which using all structures, that you want without std::hash/std::unordered_map.
namespace common
{
using std::tr1::hash;
using std::tr1::unordered_map;
using std::vector;
// and so on
}

gl.h included before glew.h?

I've been getting this error "error C1189: gl.h included before glew.h" though my includes seem to be in the right order.
I also get a 9 warnings saying "warning C4005: 'APIENTRY' : macro redefinition"
I think it may be note worthy to say that I didn't get error before switching to GLFW 3, previously I was using GLFW 2. Below is the include at the top of my "Core.h".
//External Libraries
#include <GL/glew.h>
#define GLFW_INCLUDE_GLU
#include <GLFW/glfw3.h>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
//Default Libraries
#include <cassert>
#include <stdexcept>
#include <cmath>
#include <list>
#include <iostream>
#include <string>
#include <sstream>
#include <windows.h>
I figured it out what seems to have happened is that I had a circular dependency which was also including glfw twice.

KEIL error: no instance of overloaded function "std::transform" matches the argument list

I have a problem that does no resurface (even no warnings) in XCode but does allow me to compile in Keil MDK.
void grammar::parse(std::string &_expr) {
std::transform(_expr.begin(), _expr.end(), _expr.begin(), std::tolower);
_expr.erase(std::remove_if(_expr.begin(), _expr.end(), std::isspace), _expr.end());
}
That is what I get
error: #304: no instance of overloaded function "std::transform" matches the argument list
error: #304: no instance of function template "std::remove_if" matches the argument list
Header included:
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include <stdio.h>
#include <algorithm>
Could you please advise me on where to look? I am surprised that XCode version works as expected...
You include ctype.h, that header declares a function tolower in the global namespace (this is part of the C library, so there are no other namespaces there). Maybe you meant to include cctype. For a given C standard library header X.h, there is a c++ version cX that provides some of the same functionality inside the ::std namespace.