|
David Crow wrote: I really want to know what I'm doing wrong. You are not doing anything wrong. But I think maybe you are trying to solve a problem that does not exist.
|
|
|
|
|
Interesting discussion, since i have implemented similar functionality in the passed. The only thing the user had to work with was a handle and predefined functions that take the handle as an argument.
I used this method to create STL type containers. The drawback being there was no type checking, as the data stored was just a block of memory supplied by the user.
I used a similar method when creating my old DOS interface library, it would wire up the function pointers defined in the window structure at run-time. Basically all visual elements were a window; how they were wired-up depended on the function called to create them.
You cannot created protected members, but you can created hidden members. If I remember correctly, MS uses a similar method when you create a window - there is hidden data.
The following is just off the top of my head and does not represent an actual implementation.
#define EXPHANDLE void*
EXPHANDLE ExpContainer_Create(size_t data_size, size_t count);
void ExpContainerDestroy(EXPHANDLE hExpContainer);
size_t ExpContainer_Insert(EXPHANDLE hExpContainer, void*, size_t pos);
size_t ExpContainer_Append(EXPHANDLE hExpContainer, void*);
struct ExpContainer
{
size_t data_size_;
size_t size_;
size_t used_;
void* data_;
unsigned signature_;
};
EXPHANDLE ExpContainer_Create(size_t data_size, size_t count);
{
struct ExpContainer* pContainer = malloc(sizeof(struct ExpContainer));
return (EXPHANDLE)(pContainer + offsetof(signature_));
}
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence." - Edsger Dijkstra
"I have never been lost, but I will admit to being confused for several weeks. " - Daniel Boone
|
|
|
|
|
Yes I did the same thing.
The header file did not expose the structure. It was defined in the source file and allocated/managed by the methods. Not sure if I typedef'd a handle for the void pointer or just passed the void pointer directly.
|
|
|
|
|
Aakashdata wrote: Why C is not popular among developers?
What developers are you referring to specifically? The ones here? Probably because the pool here is mainly focused on windows.
But in general it is a rather popular language and has been so for a long time.
TIOBE Index | TIOBE - The Software Quality Company[^]
|
|
|
|
|
How can I retrieve the menu color for an MDI/SDI MFC app that has MFC feature pack inside ?
I mean, I have the "Application look" menu that let me choose several theme for my app, everyone having a background color, including menu. And I intend to use this color to draw some control inside app, but I don't know how to retrieve this color ... can you help me ?
I have tried with afxGlobalData and CMFCVisualManager, none of them told me what I had need ...
modified 14-Apr-19 6:20am.
|
|
|
|
|
I have used a tabcontrol which should show different views for each tabs. As a trial, I have created a CView class and tried to show it for the first tab. When I select the tab, the appropriate view ( white screen view) is showing.
The problem is when I click on the view, it throws an assertion "Debug Assertion Failed at line: 252 in viewcore.CPP".
I have added the below code for selection of tabs.
if (nTab == 0)
{
CRect clientRect;
m_cTabCtrl.GetClientRect(&clientRect);
clientRect.DeflateRect(5, 18);
CTrendview *m_pNewView = new CTrendview();
// Creation of the view window
if(! m_pNewView->Create(NULL, NULL, WS_VISIBLE | WS_CHILD, clientRect,
&m_cTabCtrl, 1))
{
TRACE( "Failed view creation\n" );
}
m_pNewView->ShowWindow(SW_SHOW);
}
Please help me to find a solution for this problem.
|
|
|
|
|
manoharbalu wrote:
The problem is when I click on the view, it throws an assertion "Debug Assertion Failed at line: 252 in viewcore.CPP".
And what is the code "at line: 252 in viewcore.CPP" and some lines above it?
|
|
|
|
|
manoharbalu wrote: The problem is when I click on the view...I have added the below code for selection of tabs. But what does the code look like that responds to the view being clicked?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Hi,
I have an MFC application for which I have integrated OPC function using Wintech OPC DLL.
This application is an OPC Client which connects to a OPC Server and gets values from it using OPC communication.
I call the OPC functions in my application.
I used WPF(dll created by C#) in this application for some graphics and turned on the project
setting "Common Language Runtime Support (/clr)"
When I run my application in VS2008 using F5, it runs without any issues it shows correct values.
But when I run the same application using Cntrl+F5 or directly run the EXE, it runs but it shows junk values.
Notes
Suppose i change project setting from "Common Language Runtime Support (/clr)" to "No Common Language Runtime support" it is not supported WPF dll.
Please help me to find the solution for this problem
|
|
|
|
|
So, you cannot use debugger to find an error, since the program runs correctly under debugger. You need to use another debugging technique, for example, tracing.
Add TRACE/OutputDebugString messages to different parts of the program. Print results of different function calls, values of a variables etc., whatever you need to check the program. Run the program without debugger with DebugView: https://docs.microsoft.com/en-us/sysinternals/downloads/debugview Use the TRACE output to find what is wrong.
By the way, during development process, always run your program without debugging. Use debugger only if you really want to debug. This allows to prevent such situations in the future.
|
|
|
|
|
Hi
Thanks for replay. I downloaded debugview application it is also not display issue.
Still i couldn't identify the issue. Please help me
|
|
|
|
|
Try to log: at first step log the main steps of the running application, then implement smaller logging steps and so on...
|
|
|
|
|
Hello !
I have 2 classes Books and Author. On of members of Books is of type Author.
On Class Books I want to have a Constructor that takes all the parametres for book and for author :
This is my code :
class author
{
private :
string name;
string email;
public :
string get_name(){return name;}
string get_email(){return email;}
void set_name(string name){this->name=name;}
void set_email(string email){this->email=email;}
author(string name,string email)
{ this->name=name;
this->email=email;
}
}
class book
{
private :
string title;
int year;
author auth;
public:
string get_title(){return title;}
int get_year(){return year;}
void set_title(string title){this->title=title;}
void set_year(float year){this->year=year;}
book(string title, int year):author(string name,string email)
{
this->title=title;
this->year=year;
???????
}
}
I don't know how can i change the constructor of book in order that it takes all the perameter for book and for the author?
Thank you !
|
|
|
|
|
To answer your question
class book {
...
book(string title, int year, string name, string email) : auth(name, email) {
...
}
};
Some things for you to think about:
1) If you have getters and setters for all your private members, how is this different than making the private members public?
2) Although names don't usually change change (Ferdinand Lewis Alcindor Jr might disagree), emails can and do. What happens if you have a large collection of books and want to change the email of an author? There might be a better way to structure your data.
|
|
|
|
|
@1) he doesn't have a getter and setter for book::author
@2) agreed. Either the class author should really be a class author_reference, and name and email are just a (n unsuitable) choice of a unique reference to this specific author which is represented within a separate class and my contain more (private) data like home address and preferred brand of peanut butter. Or the class author really represents an actual author, in which case (s)he should only be referenced, not defined as a data member. After all, the author shouldn't die just because a book is burned...
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
|
|
|
|
|
Besides an author having multiple books, a book can also have multiple authors (including commentators).
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Presumably this is homework.
At any rate a "copy constructor" sounds quite possibly what the homework really wants you to come up with. Although perhaps the assignment is to let you copy everything first and then next demonstrate what a copy constructor is.
|
|
|
|
|
The [[nodiscard]] attribute can be use either for function return and for struct.
Both will return the same warning; Is there a better use case for the attribute ?
Either tag the struct:
struct [[nodiscard]] Patate
{
int patate;
};
Patate f1()
{
return Patate();
};
void main()
{
f1(); }
or tag the function return.
struct Patate
{
int patate;
};
[[nodiscard]] Patate f1()
{
return Patate();
};
void main()
{
f1(); }
I'd rather be phishing!
|
|
|
|
|
Your function is returning by value, which your code is ignoring (discarding).
A Google search for "attribute nodiscard" provides the answer.
C++ attribute: nodiscard (since C++17) - cppreference.com[^]
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence." - Edsger Dijkstra
"I have never been lost, but I will admit to being confused for several weeks. " - Daniel Boone
|
|
|
|
|
I know that, but the description is not clear about the differences if any between the nodiscard for the struct vs for the function.
I'd rather be phishing!
|
|
|
|
|
Well,
That attribute is weakly defined in section 10.6.7 of the standard. You can go read it yourself. The behavior is intentionally vague using words like 'encouraged' and 'discouraged'. Regardless of whether it's applied to a function or class there is no difference defined.
In fact if you carefully read the document no behavior has been defined. The only section without 'encouraged' and 'discouraged' is section 1 where the attribute token "[[nodiscard]]" itself is defined.
In other words in C++17 the only guarantee is that your compiler understand the [[nodiscard]] attribute. No behavior is defined.
Best Wishes,
-David Delaune
|
|
|
|
|
There is no difference you are discarding something (you didn't save it) that was marked as non discard.
The whole idea should have been euthanized, it is what you get when you get a committee to talk about non existent problems.
There are half a dozen real problems but they waste time on that junk.
Here is the best template to fix [nodiscard]
template < typename T >
void ignore(T&&) {}
Try it on your code
ignore(f1());
Now don't make me do it .... if I want to discard something I will
In vino veritas
modified 5-Apr-19 9:40am.
|
|
|
|
|
LOL
I think someone got tired of programmers who do not follow the good practice of checking returned values and decided to provide a standard way to warn them. The problem with that is those same programmers also tend to ignore warnings.
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence." - Edsger Dijkstra
"I have never been lost, but I will admit to being confused for several weeks. " - Daniel Boone
|
|
|
|
|
John R. Shaw wrote: ... same programmers also tend to ignore warnings.
But, but, if it compiles, I'd then not need to worry about the warnings, right?!
|
|
|
|
|
Hope can post this question on this forum.
I was under believe that triplet means three in format:
CPU-company-OS
So why is config.guess adding -gnu as fourth value?
I do not see any tangible benefits in reporting "gnu".
$ sudo bash config.guess
x86_64-pc-linux-gnu
Cheers
|
|
|
|