|
Be careful, you are heavingly doing copy of your objects.
You should pass T& when you add the object and return T& when you retrieve them.
I would also suggest to have a const version of your accessor, returning 'const T&'.
|
|
|
|
|
|
Hi,
I VS 2012 as a makefile project in the nmake properties IntelliSense Preprocessor definitions I specify _AMD64_
Yet I get the following compile error
:\Program Files\Microsoft SDKs\Windows\v7.1\Include\winnt.h(135): fatal error C1189: #error : "No Target Architecture"
|
|
|
|
|
It sounds as though your definitions are not being exported correctly, check the make file to see what it is setting.
|
|
|
|
|
Thanks
I am wondering a on makefile visual studio build where a line command is used
what role do the preprocessor flags play in the build
thanjks
|
|
|
|
|
ForNow wrote: what role do the preprocessor flags play in the build No idea, but as I said earlier, you should look at the makefile to see whether this value has been propagated correctly.
|
|
|
|
|
Hi to all,
i write a class (A) that works with an object from another class (B); class B needs to call a method from class A, but i would like this function from class A it's not visible when i use class A for my projects.
Example: i write a numeric edit that use spin button; i write a spin button class derived from CSpinButtonCtrl and an edit class derived from a CEdit; edit have a function MyFunction() called from spin button class.
So, when i use numeric edit in my projects, i would like MyFunction() (and also all class spin button) is not visible (protected).
What is the correct way to do that, if it's possible ?
Thanks
|
|
|
|
|
It seems that you are looking for friend[^].
For your example you can make your CEdit derived class a friend class of the spin control class:
class CMyEdit : CEdit {
friend class CMySpinControl;
protected:
void MyFunction();
};
|
|
|
|
|
|
As i can, i try.
Thanks to all
|
|
|
|
|
An alternative to using "friend" classes would be to use messages and message handlers. In MS Windows, messages are what windows already use to communicate with one another. You can easily add new messages and handlers.
|
|
|
|
|
(Bit late to the party... still think this is worth saying and it might help you in future)
If you ever find yourself wanting to use a class but there's aspects of it's interface that you don't want to work with then don't try and modify the class you want to use - that way lies madness and hackiness of the first degree. If the class with the relatively fat interface really needs a big interface somewhere else you don't want to break that. So what can you do about it? Wheel out the software engineer's swiss army knife - another level of indirection!
So if you've got a class:
class fat_and_dangerous
{
public:
void safe();
void dangerous();
};
and don't want clients to use dangerous() implement another class using it:
class skinny_and_safe
{
public:
skinny_and_safe() : fat_( new fat_and_dangerous ) {}
void safe() { fat_->safe(); }
private:
std::unique_ptr<fat_and_dangerous> fat_;
}
and in most of your client code only use skinny_and_safe .
Just out of interest... don't actually implement skinny_and_safe inline. It leaks too many implementation details to the client. Don't worry about performance - most compilers (actually linkers working with compilers) these days will elide the indirect call - until a profiler tells you that it's slow.
|
|
|
|
|
Thanks very much to all: it's works and it's what i need.
For Albert Holguin and Aescleal: i think with "friends" it's more simple; thanks likewise.
|
|
|
|
|
Friends will work but you should always be aware of the coupling that introduces into your design.
|
|
|
|
|
/*
William Strickland
Project 3
Is Leap Year Portion
*/
#include <stdio.h>
#include <stdlib.h>
#include "..\..\stdbool.h"
bool isLeapYear(int *year);
int main(int argc, char *argv[])
{
int year = atoi(argv[4]);
printf("Name: William Strickland \n");
printf("Is Leap Year \n");
if (isLeapYear(&year))
{
printf("%d is a leap year", year);
}
else
{
printf("%d is not a leap year", year);
}
return 0;
}
bool isLeapYear(int *year)
{
if (*year % 4 == 0 && *year % 100 != 0)
{
return 1;
}
else if (*year % 100 == 0 && *year % 400 == 0)
{
return 1;
}
else
{
return 0;
}
}
|
|
|
|
|
0. Please edit your question and wrap your code in the appropriate tags.
1. "Not running" isn't very descriptive. Are you failing to hit the enter key after typing the name of the program ina console window, are you only building the program but not running it from an IDE, or perhaps, you're running the program and it produces unexpected output..
2. The program runs just fine.
3. This is the output I get when running from the console. (I assume you understand what argv[4] refers to. Hint: it's not a 4 character long input. argv[0] would hold "001-deleteMePlease" "001-deleteMePlease.exe")
D:\code\001-deleteMePlease\bin\Release>001-deleteMePlease.exe 1 2 3 2000
Name: William Strickland
Is Leap Year
2000 is a leap year
"When I was 5 years old, my mother always told me that happiness was the key to life. When I went to school, they asked me what I wanted to be when I grew up. I wrote down 'happy'. They told me I didn't understand the assignment, and I told them they didn't understand life." - John Lennon
|
|
|
|
|
Hi there,
I have learned the principles of OOP and implementations in both java and C++ either on my own or in my school courses but we only grazed it. At this point, I feel very uncomfortable with OOP and I need a good resource that will provide me with a great deal of problems that require OOP to solve (or are best solved using object oriented approaches), and their respective answers with clean code and good practices. I have had very very little practice with OOP and want to practice as much as possible to get comfortable with it. I have been searching a lot but I can't seem to find a good resource.
Optimally, I would like it to begin with very trivial questions and progressively become more and more difficult.
Thank you.
|
|
|
|
|
|
|
4india wrote: I think you can refer this refer this site for knowledge buildup. I think not; the first example I looked at is wrong.
|
|
|
|
|
He's just spamming - why would he care if it works?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Correct, more votes still needed.
|
|
|
|
|
Hi,
I want to generate a dump file automatically whenever the application crashed/hanged. Is there any option to do it or how to do it programatically as the developer don't know when that application crashes at client location.
Thanks in advance for your help.
|
|
|
|
|
AFAIK Dump Files are managed by the OS - whichever it is - so you should look on the OS documentation. It is probable that you need to instruct the OS that you want a dump file and of which kind you desire (short, long, kernel...).
For example see if
http://msdn.microsoft.com/en-us/library/d5zhxt22.aspx[^]
is of any use for you.
HTH
|
|
|
|
|
Hi,
Thanks for your reply.
|
|
|
|