description | title | ms.date | f1_keywords | helpviewer_keywords | ms.assetid |
---|---|---|---|---|---|
Learn more about: Compiler Error C2535 |
Compiler Error C2535 |
11/04/2016 |
C2535 |
C2535 |
a958f83e-e2bf-4a59-b44b-d406ec325d7e |
Compiler Error C2535
‘identifier’ : member function already defined or declared
This error could be caused by using the same formal parameter list in more than one definition or declaration of an overloaded function.
If you get C2535 because of the Dispose function, see Destructors and finalizers for more information.
The following sample generates C2535:
// C2535.cpp // compile with: /c class C { public: void func(); // forward declaration void func() {} // C2535 };
- Remove From My Forums
-
Question
-
Hi, i got error C2535, and more, when I try to compile my project in release config. these happens only with the inl files, I include the file Soldier.inl on the header file of the class Soldier, of course all my inl files give me these error, I don’t know if the compiler config is unable to compile inl files.
I need help, thanks
1>e:visual studio 2005projectsevilseedSoldier.inl(17) : error C2535: ‘CollisionManager::IntersectionRecord &Soldier::GetIntersectionRecord(void)’ : member function already defined or declared 1> e:visual studio 2005projectsevilseedSoldier.h(39) : see declaration of ‘Soldier::GetIntersectionRecord’
it’s «Soldier.h»
#ifndef SOLDIER_H
#define SOLDIER_H
#include ….
class Soldier
{
public:
…
CollisionManager::IntersectionRecord& GetIntersectionRecord();
…
private:
CollisionManager::IntersectionRecord m_kIntersectionRecord;
}
#include «Soldier.inl»
#endif //#ifndef SOLDIER_H
and the inl file «soldier.inl» is like that
//————————————————————————— // Soldier inline functions //————————————————————————— inline CollisionManager::IntersectionRecord& Soldier::GetIntersectionRecord() { return m_kIntersectionRecord; } //—————————————————————————
Answers
-
thanks nobugz, don’t worry about the semi-colon, it’s in the original code
That is a problem, unless we can get an ACCURATE representation of the code then it is impossible to give any reasonable help.
But the answer is still simple. The error C2535 tells you exactly as it is.
A simple example like the following also works pefectly.
class testclass
{
public:
int inlfun();
};inline int testclass::inlfun()
{
return 0;
}So it is a simple case of not enough info about the mistake you or whoever wrote the code made.
Visit my (not very good) blog at http://c2kblog.blogspot.com/
-
Marked as answer by
Wednesday, October 7, 2009 2:32 AM
-
Marked as answer by
-
It seems the header files are mutual coupling, to use the SDK header and library files correctly, the recommended way is putting them at the begining of Include files and Library files in Tools->Options->Projects and Solutions->VC++ Directories.
Sincerely,
Wesley
Please mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.-
Marked as answer by
Wesley Yao
Wednesday, October 7, 2009 2:31 AM
-
Marked as answer by
1ые 1 / 1 / 0 Регистрация: 19.01.2013 Сообщений: 98 |
||||
1 |
||||
31.01.2014, 02:44. Показов 1449. Ответов 2 Метки нет (Все метки)
Доброго времени суток начал изучать STL и пытаюсь соответственно активно использовать
на что компилятор гордо заявил:
0 |
Programming Эксперт 94731 / 64177 / 26122 Регистрация: 12.04.2006 Сообщений: 116,782 |
31.01.2014, 02:44 |
Ответы с готовыми решениями: Как поменять цвет TextView в адапторе? bind1st и bind2nd int… Непонятки с bind2nd Использование bind2nd 2 |
Форумчанин 8194 / 5044 / 1437 Регистрация: 29.11.2010 Сообщений: 13,453 |
|
31.01.2014, 06:35 |
2 |
Попробуйте у string убрать ссылки в строках 8 и 13.
1 |
Ilot 2013 / 1342 / 382 Регистрация: 16.05.2013 Сообщений: 3,463 Записей в блоге: 6 |
||||
31.01.2014, 09:21 |
3 |
|||
Смотрите реализацию адаптера bind2nd: Кликните здесь для просмотра всего текста
У вас аргументы в вызове функции класса OBJ передаются по ссылке однако оператор вызова функции адаптера константный и не может изменить переданные ему аргументы. Для изменения контейнера изпользуйте алгоритм transform. Кстати использование итератора вставки приветствуется.
1 |
IT_Exp Эксперт 87844 / 49110 / 22898 Регистрация: 17.06.2006 Сообщений: 92,604 |
31.01.2014, 09:21 |
3 |
I’m getting a strange C2535-compiler error while trying to compile the following code:
template<int NUMBER>
class Container {
public:
bool operator==(const Container& other) const { return true; }
};
namespace std {
template <int NUMBER>
class hash<Container<NUMBER>> {
public:
size_t operator()(const Container<NUMBER> & state) const {
return 0;
}
};
}
int main(int argc, char* argv[]){
auto* b = new std::unordered_map< Container<1>, int>(); //C2535
}
Note that if I use a my own template-based Hasher
template<int NUMBER>
class Hash {
public:
size_t operator()(const Container<NUMBER> & state) const {
return 0;
}
};
int main(int argc, char* argv[]){
auto* b = new std::unordered_map< Container<1>, int, Hash<1>>();
}
the code compiles just fine. And I remember that the code was being compiled without a hitch in Visual Studio 2013 Express.
Question: Is this a VS 2015 — bug or is this behaviour in some way standard-conforming?
asked Apr 25, 2015 at 11:02
5
Actually, this is made ill-formed by a subtlety in §14.5.1/4:
In a redeclaration, partial specialization, explicit specialization or
explicit instantiation of a class template, the class-key shall agree
in kind with the original class template declaration (7.1.6.3).
And, according to §20.9/2, hash
is declared as
Header
<functional>
synopsis// 20.9.12, hash function primary template: template <class T> struct hash;
Hence try
template <int NUMBER>
struct hash<Container<NUMBER>> { /*…*/ };
instead.
answered Apr 25, 2015 at 11:18
ColumboColumbo
59.8k8 gold badges153 silver badges202 bronze badges
0
Я пытаюсь решить этот вопрос в Facebook
http://learn.hackerearth.com/question/383/staves/
И я делаю ошибку
error C2535: 'std::vector<_Ty> &std::map<_Kty,Staves::SubStringVector &>::operator [](const std::basic_string<_Elem,_Traits,_Alloc> &)'
: member function already defined or declared
c:program files (x86)microsoft visual studio 11.0vcincludemap 191 1 FB-Staves
Я совершенно не знаю, почему я получаю эту ошибку, может кто-то, пожалуйста, помогите мне определить проблему в моем коде?
Благодаря Sameer
Мой код показан ниже:
#include "stdafx.h"
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
using namespace std;
class Staves
{
public:
struct SubString
{
std::string str;
unsigned int startPos;
unsigned int endPos;
};
struct PositionalComparer
{
bool operator()(const SubString* s1, const SubString* s2)
{
return s1->startPos < s2->startPos;
}
} PositionalComparer;
typedef std::vector<const SubString*> SubStringVector;
typedef std::map<const std::string&, SubStringVector&> SubStringMap;
public:
Staves()
{
};
virtual ~Staves()
{
for(unsigned int i = 0; i < m_vec.size(); ++i)
{
delete m_vec[i];
}
}
public:
void AddSubString(const std::string& input, unsigned int startPos, unsigned int endPos)
{
SubString* subStr = new SubString();
subStr->str = input.substr(startPos, endPos - startPos);
std::sort(subStr->str.begin(), subStr->str.end());
subStr->startPos = startPos;
subStr->endPos = endPos;
m_vec.push_back(subStr);
};
bool PrintStavesIfAny()
{
SubStringMap subStrMap;
for(unsigned int i = 0; i < m_vec.size(); ++i)
{
const std::string& s1 = m_vec[i]->str;
if(subStrMap.find(s1) != subStrMap.end())
{
SubStringVector& v1 = subStrMap[s1];
v1.push_back(m_vec[i]);
}
else
{
SubStringVector v2;
v2.push_back(m_vec[i]);
subStrMap[s1] = v2;
}
}
// Now that our map is ready, iterate and find a pair
// of substrings that do not overlap
SubStringMap::iterator itr = subStrMap.begin();
for(; itr != subStrMap.end(); ++itr)
{
if(PrintStavesIfAny(itr->second))
{
return true;
}
}
return false;
};
private:
bool PrintStavesIfAny(SubStringVector& vec)
{
std::sort(vec.begin(), vec.end(), PositionalComparer);
const SubString* s = vec[0];
for(unsigned int i = 1; i < vec.size(); ++i)
{
if(vec[i]->endPos > s->endPos)
{
cout << s->startPos << " " << vec[i]->startPos << " " << s->str.size() << endl;
return true;
}
}
return false;
};
private:
SubStringVector m_vec;
};
void PrintStaves(const string& str)
{
unsigned int currentLen = str.size() / 2;
unsigned int currentPos = 0;
while(currentLen != 0)
{
// find all substrings of length currentLen
currentPos = 0;
Staves* staves = new Staves();
while(currentPos + currentLen < str.size())
{
staves->AddSubString(str, currentPos, currentPos + currentLen);
++currentPos;
}
// Done adding all substrings of currentLen, now find if a stave exists
if(staves->PrintStavesIfAny())
{
return;
}
// make a fresh beginning for a shorter stave
delete staves;
--currentLen;
}
}
int _tmain(int argc, _TCHAR* argv[])
{
string str = "131251141231";
//getline(cin, str);
PrintStaves(str);
return 0;
}