I have a memory leak that I’m trying to hunt down in my mfc program. Typically I would do something like the following:
header file
// Leak Detection
#if defined(WIN32) && defined(_DEBUG)
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#endif
cpp file
// Leak detection
#if defined(WIN32) && defined(_DEBUG) && defined(_CRTDBG_MAP_ALLOC)
#ifdef DEBUG_NEW
#undef DEBUG_NEW
#endif
#define DEBUG_NEW new( _NORMAL_BLOCK, __FILE__, __LINE__ )
#define new DEBUG_NEW
#endif
This technique works well in most files, but when I include it in some files such as my document, I get the error: error C2661: ‘CObject::operator new’ : no overloaded function takes 4 arguments
What’s the solution here? Should I be #undef-ing new somewhere or something?
Thanks!
asked Jun 8, 2012 at 16:33
5
I also use the same functionality as you for the purpose of leak detection.
Either you can comment out or delete the DEBUG_NEW definition block, assuming you don’t need it any more for trapping memory leaks. Or if you still need it, leave it as it is and use
#ifdef _DEBUG
#undef new
CMyOject* pMyObjectInst = new CMyObject();
#define new DBG_NEW
#endif
So, you undefine new just before object creation (see the line numbers in your Error List) and redefine it again immediately after, so that any memory leaks which occur after this object creation are still identifiable.
answered Oct 16, 2012 at 12:15
I have similar problem caused by putting #define new DEBUG_NEW
before #include ...
statements in .cpp file. Changing the order resolved my problem.
answered Jul 18, 2013 at 8:23
BFG1992 0 / 0 / 0 Регистрация: 20.11.2012 Сообщений: 5 |
||||
1 |
||||
20.11.2012, 21:38. Показов 17087. Ответов 2 Метки нет (Все метки)
Здравствуйте, уважаемые посетители сего форума. Набирал лабу, столкнулся вот с такой проблемой. Скриншот и код прилагаю:
Поиск по гуглу ничего не дал. Буду очень благодарен любой помощи, желательно — с пояснениями, что я сделал не так Миниатюры
0 |
Programming Эксперт 94731 / 64177 / 26122 Регистрация: 12.04.2006 Сообщений: 116,782 |
20.11.2012, 21:38 |
Ответы с готовыми решениями: Нет перегруженной функции, принимающей 2 аргументов Базовый класс:… Ошибка «нет перегруженной функции, принимающей 2 аргументов» «Нет перегруженной функции, принимающей 3 аргументов» Pow: нет перегруженной функции 2 |
2378 / 1662 / 279 Регистрация: 29.05.2011 Сообщений: 3,396 |
|
20.11.2012, 21:42 |
2 |
pow(cos(x)) В какую степень возводится косинус?
1 |
0 / 0 / 0 Регистрация: 20.11.2012 Сообщений: 5 |
|
20.11.2012, 21:47 [ТС] |
3 |
grizlik78, ох блин… Как я мог не заметить
0 |
I’m trying to create a class that contains structs of the following types:
struct gameObject
{
int row; // row position of the object
int column; // column position of the object
bool isFound; // flag to indicate if the object has been found (or is dead, in the case of the monster)
bool isVisible; // flag to indicate if the object can be seen on the board -add in week 4
};
struct playerObject
{
bool alive; // flag to indicate if the player is alive or dead
bool hasWeapon; // flag to indicate if the player has the weapon
bool hasTreasure; // flag to indicate if the player has the treasure
bool hasTorch; // flag to indicate if the player has the torch -add in week 4
bool hasNoisemaker; // flag to indicate if the player has the noisemaker -add in week 4
bool hasKey;
gameObject position; // variables for row, column and visibility
};
I’m doing this so I can have all of my «game pieces» and their data under one object to hopefully help with readability.
The class I’m trying to declare is below:
class pieces{//the class for the game and player objects
public:
pieces();
~pieces();
gameObjectType hold = EMPTY; // Holds objects under the monster<bug fix>
// </WK6>
playerObject player = { true, false, false, false, false, false, { -1, -1, false, true } }; // the player
gameObject treasure ={ -1, -1, false, true }; // the treasure
gameObject monster = { -1, -1, false, true }; // the monster
gameObject weapon = { -1, -1, false, true }; // the weapon
gameObject torch = { -1, -1, false, true }; // the torch
gameObject noisemaker = { -1, -1, false, true }; // the noisemaker
gameObject key = { -1, -1, false, true };
gameObject caveExit = { -1, -1, false, true }; // the cave exit
};
The problem is that I keep getting a C2661 error. For all of my gameObject declarations it says error C2661: 'gameObject::gameObject' : no overloaded function takes 4 arguments
However, for my playerObject, it says the same except with 7 arguments instead of 4.
I’ve been at it for hours and I can’t figure out what’s going on.
поэтому я работаю с C ++ Primer и пытаюсь изменить один из примеров книги, чтобы использовать структуру и вектор, используя указанную структуру для хранения, а затем вызвать элементы указанного вектора для печати.
Для этого я используюemplace_back()
и передать ему два целочисленных аргумента для удовлетворения двух целочисленных объявлений в структуре, а затем поместить эту структуру в вектор (я полагаю).
Тем не менее, я продолжаю получать сообщение об ошибке «C2661:« matrix :: matrix »: ни одна перегруженная функция не принимает 2 аргумента», когда я пытаюсь отладить программу. Я не слишком уверен, что происходит, и я не могу понять другие объяснения, данные людям с той же проблемой. Программа работает в основном нормально, как написано в книге (она компилируется и не умирает), но я пытаюсь включить то, что я изучил в Accelerated C ++, в Primer.
Помочь новичку? Вот что у меня есть:
#include <iostream>
#include <vector>
struct matrix //create struct
{
int value;
int count;
};
void printRepeats(std::vector<matrix>& e, std::vector<matrix>::size_type& r)
{
std::cout << e[r].value << e[r].count; // print elements of struct
}
int main()
{
std::vector<matrix> repeats;
int currVal = 0;
int val = 0;
if (std::cin >> currVal)
{
int cnt = 0;
while (std::cin >> val)
{
if (val == currVal)
{
++cnt;
}
else
{
repeats.emplace_back(currVal, cnt);
currVal = val;
cnt = 0;
}
}
}
for (std::vector<matrix>::size_type r(0); r != repeats.size(); r++)
{
printRepeats(repeats, r);
}
std::cin.get();
std::cin.get();
return 0;
}
0
Решение
@ Borgleader прав, конечно. Но тогда Борг всегда есть.
Таким образом, чтобы собрать его, все, что вам нужно сделать, это изменить это:
struct matrix
{
int value;
int count;
};
К этому:
struct matrix
{
matrix (int value, int count) : value (value), count (count) {} // constructor
int value;
int count;
};
И пошли.
Посмотрите на Wandbox: https://wandbox.org/permlink/zzRRzdQjjG1vm4tM
2
Другие решения
Других решений пока нет …
- Remove From My Forums
-
Question
-
Hi,
I am trying to use a SendMessage API function, but I get «error C2661: ‘System::Windows::Forms::Control::SendMessage’ : no overloaded function takes 4 arguments».
Here is the piece of code:
[DllImport("user32.dll", CharSet = CharSet::Auto)] static int SendMessage(IntPtr hWnd, int wMsg, int wParam, int lParam);
void ScrollToEnd(RichTextBox^ rtb) { const int WM_VSCROLL = 277; const int SB_BOTTOM = 7; SendMessage(rtb->Handle, WM_VSCROLL, SB_BOTTOM, 0); }
What am I doing wrong ?
Answers
-
Oh well, found the root cause, once you mentioned the ‘class name’. I’ve had SendMessage defined under namespace, but it needs to be be defined under the class of course.
That fixed the problem.
Thanks
-
Marked as answer by
Monday, March 30, 2009 9:30 AM
-
Marked as answer by