description | title | ms.date | f1_keywords | helpviewer_keywords | ms.assetid |
---|---|---|---|---|---|
Learn more about: Compiler Error C3867 |
Compiler Error C3867 |
11/04/2016 |
C3867 |
C3867 |
bc5de03f-e01a-4407-88c3-2c63f0016a1e |
Compiler Error C3867
‘func’: function call missing argument list; use ‘&func’ to create a pointer to member
You tried to take the address of a member function without qualifying the member function with its class name and the address-of operator.
This error can also be generated as a result of compiler conformance work that was done for Visual Studio 2005: enhanced pointer-to-member conformance. Code that compiled prior to Visual Studio 2005 will now generate C3867.
Examples
C3867 can be issued from the compiler with a misleading suggested resolution. Whenever possible, use the most derived class.
The following sample generates C3867 and shows how to fix it.
// C3867_1.cpp // compile with: /c struct Base { protected: void Test() {} }; class Derived : public Base { virtual void Bar(); }; void Derived::Bar() { void (Base::*p1)() = Test; // C3867 &Derived::Test; // OK }
The following sample generates C3867 and shows how to fix it.
// C3867_2.cpp #include<stdio.h> struct S { char *func() { return "message"; } }; class X { public: void f() {} }; int main() { X::f; // C3867 // OK X * myX = new X; myX->f(); S s; printf_s("test %s", s.func); // C3867 printf_s("test %s", s.func()); // OK }
The following sample generates C3867 and shows how to fix it.
// C3867_3.cpp class X { public: void mf(){} }; int main() { void (X::*pmf)() = X::mf; // C3867 // try the following line instead void (X::*pmf2)() = &X::mf; }
The following sample generates C3867.
// C3867_4.cpp // compile with: /c class A { public: void f(int) {} typedef void (A::*TAmtd)(int); struct B { TAmtd p; }; void g() { B b1; b1.p = f; // C3867 } };
The following sample generates C3867.
// C3867_5.cpp // compile with: /EHsc #include <iostream> class Testpm { public: void m_func1() { std::cout << m_num << "tm_func1n"; } int m_num; typedef void (Testpm::*pmfn1)(); void func(Testpm* p); }; void Testpm::func(Testpm* p) { pmfn1 s = m_func1; // C3867 pmfn1 s2 = &Testpm::m_func1; // OK (p->*s2)(); } int main() { Testpm *pTestpm = new Testpm; pTestpm->m_num = 10; pTestpm->func(pTestpm); }
MoonRaiser 1 / 1 / 0 Регистрация: 11.11.2016 Сообщений: 66 |
||||
1 |
||||
02.04.2017, 09:05. Показов 3312. Ответов 5 Метки visual studio 2015 (Все метки)
Вызывает ошибку C3867. «System::Windows::Forms::Control::Invalidate»: нестандартный синтаксис; используйте «&», чтобы создать указатель на член Что сделать то нужно? И почему тогда vs сама предлагает так писать и подставляет такой вариант, коли при компиляции выкидывает ошибку?
__________________
0 |
Programming Эксперт 94731 / 64177 / 26122 Регистрация: 12.04.2006 Сообщений: 116,782 |
02.04.2017, 09:05 |
Ответы с готовыми решениями: Error C3867: «String::length»: нестандартный синтаксис; используйте «&», чтобы создать указатель на член нестандартный синтаксис используйте «&», чтобы создать указатель на член C3867 «Нестандартный синтаксис, используйте «&», чтобы создать указатель на член» Не могу создать указатель на функцию. ошибка: нестандартный синтаксис; используйте «&», чтобы создать указатель на член 5 |
rao 902 / 423 / 159 Регистрация: 02.04.2014 Сообщений: 1,206 |
||||
02.04.2017, 10:08 |
2 |
|||
Сообщение было отмечено MoonRaiser как решение Решениеты же метод вызываешь, поэтому ставь скобочки:
1 |
1 / 1 / 0 Регистрация: 11.11.2016 Сообщений: 66 |
|
02.04.2017, 10:22 [ТС] |
3 |
rao, а в чем тогда отличие между invalidate и refresh?
0 |
Администратор 15248 / 12287 / 4904 Регистрация: 17.03.2014 Сообщений: 24,884 Записей в блоге: 1 |
|
02.04.2017, 13:26 |
4 |
MoonRaiser, ответ есть в документации Control::Invalidate — Invalidates the entire surface of the control and causes the control to be redrawn. Invalidate говорит что отображение элемента устарело и его нужно перерисовать, Refresh говорит что отображение элемента устарело и перерисовывает его.
1 |
1 / 1 / 0 Регистрация: 11.11.2016 Сообщений: 66 |
|
02.04.2017, 13:38 [ТС] |
5 |
OwenGlendower, т.е. invalidate в конечном счетё вызывает refresh? Документацию предварительно читал, но этот вопрос не отпал.
0 |
Администратор 15248 / 12287 / 4904 Регистрация: 17.03.2014 Сообщений: 24,884 Записей в блоге: 1 |
|
02.04.2017, 14:02 |
6 |
MoonRaiser, Invalidate не вызывает Refresh. Он только уведомляет ОС что нужно перерисовать окно или его часть. При следующем WM_PAINT (метод Paint) это и произойдет. То есть Refresh это немедленная перерисовка, а Invalidate отложенная.
1 |
IT_Exp Эксперт 87844 / 49110 / 22898 Регистрация: 17.06.2006 Сообщений: 92,604 |
02.04.2017, 14:02 |
Помогаю со студенческими работами здесь Нестандартный синтаксис, используйте «&», чтобы создать указатель на член #include… Поиск в массиве. Ошибка «Оператор «&&» не может применяться к операндам типа «bool» и «double»» Где ошибка невозможно преобразовать указатель «this» из «const pers» в «pers &» при выводе объектов через cout Как написать регулярное выражение для выдергивания английских букв и символов: «+», «,», «:», «-«, » «, «!», «?» и «.» Искать еще темы с ответами Или воспользуйтесь поиском по форуму: 6 |
I’m upgrading a game engine’s source code from Visual Studio 2003 to Visual Studio 2008. When I try and compile the source code I get the following error.
error C3867: ‘UObject::StaticConstructor’: function call missing argument list; use ‘&UObject::StaticConstructor’ to create a pointer to member
in the following code:
//----(IMPLEMENT_CLASS macro):
#define IMPLEMENT_CLASS(TClass)
UClass TClass::PrivateStaticClass
(
EC_NativeConstructor,
sizeof(TClass),
TClass::StaticClassFlags,
TClass::Super::StaticClass(),
TClass::WithinClass::StaticClass(),
FGuid(TClass::GUID1,TClass::GUID2,TClass::GUID3,TClass::GUID4),
TEXT(#TClass)+1,
GPackage,
StaticConfigName(),
RF_Public | RF_Standalone | RF_Transient | RF_Native,
(void(*)(void*))TClass::InternalConstructor,
(void(UObject::*)())TClass::StaticConstructor /* ERROR ON THIS LINE */
);
extern "C" DLL_EXPORT UClass* autoclass##TClass;
DLL_EXPORT UClass* autoclass##TClass = TClass::StaticClass();
Note: This code snippet is from http://www.experts-exchange.com/Programming/Languages/CPP/Q_20756876.html (Needless to say they are exactly same)
I am not sure how should I re-write the line so that there are no errors.
(void(UObject::*)())TClass::StaticConstructor
Hi all,
I am now trying to run a discrete event simulation using MSVC++2005, After built it shows the following error:….
portion of the header file is:
#ifndef _DESL_H_V003_INCLUDED_
#define _DESL_H_V003_INCLUDED_
#include <crtdbg.h> // needed for _ASSERT() macro
#include «avltree.h»
#include «_stack.h»
#include «_list.h»
/////////////////////////////////////////////////////////////////////////
// CLASS: template < class TIME_T, class DATA_T >
// class DESL_environment
//
// PURPOSE: use as ‘parameterized namespace’
/////////////////////////////////////////////////////////////////////////
#define DESL_QUALIFIER DESL_environment< TIME_T, DATA_T >
template < class TIME_T, class DATA_T > class DESL_environment
{
/////////////////////////////////////////////////////////////////////////
private:
/////////////////////////////////////////////////////////////////////////
// Make constructors private to prevent creation of objects
// of type DESL_environment< TIME_T, DATA_T >
DESL_environment() {};
DESL_environment( const DESL_QUALIFIER& ) {};
/////////////////////////////////////////////////////////////////////////
public:
/////////////////////////////////////////////////////////////////////////
#define ACTIVATION_TIME NodeKey
extern class CEvent;
extern class CEventQueue;
extern class CBase;
friend class CBase;
typedef TIME_T time_t; // event time
typedef DATA_T data_t; // data associated with each event
typedef int16s obid_t; // object id
typedef class CBase base_t; // base class for all DESL classes
typedef class CEvent evnt_t; // CEvent class
/////////////////////////////////////////////////////////////////////
// CLASS: class CEvent : public AVLNode
// PURPOSE: Represents an Event that can be stored in and
// retrieved from the Event queue (CEventQueue)
/////////////////////////////////////////////////////////////////////
class CEvent : private AVL::AVLNode< time_t >, public data_t
{
friend class CEventQueue;
friend class Stack< evnt_t >;
/////////////////////////////////////////////////////////////////////
private:
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
// Make constructor and destructor private to ensure that
// events are created and destroyed only by CEventQueue class
/////////////////////////////////////////////////////////////////
CEvent() : AVL::AVLNode< time_t >(0)
{
Consumer = NULL;
Producer = NULL;
Activate();
}
CEvent( CEvent& event ) : AVL::AVLNode< time_t >(0)
{
*this = event;
Activate();
}
~CEvent() {}
// the following methods are used to make class CEvent stackable
inline void SetNext( evnt_t* p ) { RChild = p; }
inline void SetPrev( evnt_t* p ) { LChild = p; }
inline evnt_t* GetNext( void ) const { return (evnt_t*) RChild; }
inline evnt_t* GetPrev( void ) const { return (evnt_t*) LChild; }
/////////////////////////////////////////////////////////////////
// When the event is stored in an event queue, it’s right child
// and left child pointers can never point to itself.
// If the pointers point to itself, that means the even is active
/////////////////////////////////////////////////////////////////
inline void Activate( void ) { RChild = LChild = this; }
inline BOOL IsActive( void ) const { return GetNext() == this
&& GetPrev() == this; }
//inline time_t GetTime( void ) const { return ACTIVATION_TIME; }
/////////////////////////////////////////////////////////////////////
public:
/////////////////////////////////////////////////////////////////////
base_t* Producer; // pointer to producer of the event
base_t* Consumer; // pointer to consumer of the event
};
The error msg:
Rebuild All started: Project: pallab3, Configuration: Debug Win32 ——
Deleting intermediate and output files for project ‘pallab3’, configuration ‘Debug|Win32’
Compiling…
sl_main.cpp
c:program filesmicrosoft visual studio 8vcincludesim_output.h(67) : warning C4996: ‘strcat’ was declared deprecated
C:Program FilesMicrosoft Visual Studio 8VCincludestring.h(78) : see declaration of ‘strcat’
Message: ‘This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.’
c:program filesmicrosoft visual studio 8vcincludesim_output.h(94) : warning C4996: ‘strcat’ was declared deprecated
C:Program FilesMicrosoft Visual Studio 8VCincludestring.h(78) : see declaration of ‘strcat’
Message: ‘This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.’
c:program filesmicrosoft visual studio 8vcincludesim_output.h(133) : warning C4996: ‘strcat’ was declared deprecated
C:Program FilesMicrosoft Visual Studio 8VCincludestring.h(78) : see declaration of ‘strcat’
Message: ‘This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.’
Using CONFIGURATION file …… c:program filesmicrosoft visual studio 8vcincludeconf_001.h
Using SIMULATION file ……… c:program filesmicrosoft visual studio 8vcincludetest_001.h
d:simulation filesSimulationList of filessl_main.cpp(61) : warning C4996: ‘localtime’ was declared deprecated
C:Program FilesMicrosoft Visual Studio 8VCincludetime.inl(114) : see declaration of ‘localtime’
Message: ‘This function or variable may be unsafe. Consider using localtime_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.’
d:simulation filesSimulationList of filessl_main.cpp(71) : warning C4996: ‘_snprintf’ was declared deprecated
C:Program FilesMicrosoft Visual Studio 8VCincludestdio.h(339) : see declaration of ‘_snprintf’
Message: ‘This function or variable may be unsafe. Consider using _snprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.’
d:simulation filesSimulationList of filessl_main.cpp(85) : warning C4996: ‘ctime’ was declared deprecated
C:Program FilesMicrosoft Visual Studio 8VCincludetime.inl(88) : see declaration of ‘ctime’
Message: ‘This function or variable may be unsafe. Consider using ctime_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.’
c:program filesmicrosoft visual studio 8vcincludedesl.h(436) : error C3867: ‘DESL_environment<TIME_T,DATA_T>::CBase::Reset’: function call missing argument list; use ‘&DESL_environment<TIME_T,DATA_T>::CBase::Reset’ to create a pointer to member
with
[
TIME_T=int64s,
DATA_T=EventData
]
c:program filesmicrosoft visual studio 8vcincludedesl.h(434) : while compiling class template member function ‘void DESL_environment<TIME_T,DATA_T>::GlobalReset(void)’
with
[
TIME_T=int64s,
DATA_T=EventData
]
C:Program FilesMicrosoft Visual Studio 8VCincludesim_config.h(118) : see reference to class template instantiation ‘DESL_environment<TIME_T,DATA_T>’ being compiled
with
[
TIME_T=int64s,
DATA_T=EventData
]
Build log was saved at «file://c:Documents and SettingsTC28My DocumentsVisual Studio 2005Projectspallab3pallab3DebugBuildLog.htm»
pallab3 — 1 error(s), 6 warning(s)
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
Can anyone please help me ?….
Thanks
pallab
The error I’m getting is:
Severity Code Description Project File Line Suppression State
Error C3867 'std::vector<objManager::obj,std::allocator<_Ty>>::size': non-standard syntax; use '&' to create a pointer to member SFMLThing c:usersmesourcerepossfmlthingsfmlthingobjmanager.cpp 23
The line of code that’s it pointing at
#include "objManager.h"
#include <SFMLGraphics.hpp>
#include <iostream>
#include <vector>
objManager::objManager()
{
std::cout << "[objManager class added]n";
}
void objManager::addObj(sf::Color clr, sf::Vector2f pos, sf::Vector2f size, bool col)
{
obj newObj;
newObj.body.setFillColor(clr);
newObj.body.setPosition(pos);
newObj.body.setSize(size);
newObj.col = col;
objs.push_back(newObj);
}
void objManager::Draw(sf::RenderWindow& window)
{
for (int i = objs.size; i > 0; i--) { //23 Line [C3867]
window.draw(objs[i].body);
}
}
(Edit) Here’s the header file for it
#include <iostream>
#include <SFMLGraphics.hpp>
#include <vector>
#pragma once
class objManager
{
public:
objManager();
void addObj(sf::Color clr,sf::Vector2f pos,sf::Vector2f size,bool col);
void Draw(sf::RenderWindow&);
private:
int objAmount=0;
struct obj {
sf::RectangleShape body;
bool col;
};
std::vector<obj> objs;
};
I’m a beginner at C++ and SFML, some help would be appreaciated, thanks!
В моем коде в Visual Studio 2015 у меня есть интерфейс:
struct IStr
{
virtual std::ostream& beginMessage() = 0;
virtual std::ostream& endMessage(std::ostream&) = 0;
};
И у меня есть класс, который реализует этот интерфейс, например:
#include <sstream>
struct MyStr : public IStr
{
std::stringstream m_stream;
std::ostream& beginMessage() override { return m_stream; }
std::ostream& endMessage(std::ostream& ss) override { return std::endl(ss); }
};
Тем не менее, я получаю сообщение об ошибке при попытке скомпилировать простой код:
IStr * pStr = new MyStr();
pStr->beginMessage() << "Hello Wordl!" << pStr->endMessage;
С сообщением:
Error C3867
'IStr::endMessage': non-standard syntax; use '&' to create a pointer to member
Мне очень нравится синтаксис, который я пытаюсь использовать. Но возможно ли это? Может быть проблема в том, что мой манипулятор является виртуальным или нестатичным?
0
Решение
Используйте NVI и endMessage()
вернуть (сохраняющий состояние) манипулятор, который вызывает виртуальную функцию в потоке при потоковой передаче.
struct IStr
{
// other stuff
private:
virtual std::ostream& doBeginMessage() = 0;
virtual std::ostream& doEndMessage(std::ostream&) = 0;
struct EndManip{
IStr* istr;
};
friend std::ostream& operator<<(std::ostream& ss, EndManip em){
return em.istr->doEndMessage(ss);
}
public:
EndManip endMessage() { return {this}; }
std::ostream& beginMessage() { return doBeginMessage(); }
};
С этим ты бы сделал pStr->beginMessage() << "Hello World!" << pStr->endMessage();
,
3
Другие решения
Ты написал:
IStr * pStr = new MyStr();
pStr->beginMessage() << "Hello Wordl!" << pStr->endMessage;
в то время как вы должны были написать что-то похожее на:
IStr * pStr = new MyStr();
pStr->beginMessage() << "Hello Wordl!" << pStr->endMessage(*pStream);
Разница здесь заключается в (), который приводит к выполнению вызова функции вместо попытки передать указатель на функцию (что, скорее всего, не является вашим намерением).
1