15,902,112 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View Python questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by Aswin Waiba (Top 14 by date)
Aswin Waiba
10-Dec-13 3:21am
View
Deleted
<pre lang="xml"><choice> </pre>
Aswin Waiba
4-Dec-13 23:05pm
View
a piece of code like that is present in our project. Don't really understand what it was trying to achieve though :(
Aswin Waiba
28-Nov-13 23:45pm
View
Actually that is just a simplified function. The helper class file contains a lot of templatized classes, each fullfilling a particular function. And As from the above example the MainClass function definitions in helperclass.h uses those templatized classes. However some functions of HelperClass (es) also directly use the static member of MainClass. I want to separate out the two, and at the same time provide access to the static member of MainClass.
Another point to note is HelperClass(es) is derived from HelperParentClass and all the functions are virtual.
Most of the other function of MainClass access HelperClass objects via HelperParentClass pointer.
Aswin Waiba
16-Aug-13 8:31am
View
No, you don't have two definitions of the vector class. You have two *instances* of the vector class. True
But say
when u instantiate vector as
vector<int> obj1;
vector<float> obj2;
means ultimately there will two classes vector<int> and vector<float>
Each time you declare an int, you're not giving the definition of an int, you're simply declaring a variable and telling the compiler that it's an int. True.
But this is true only for integral data types and non-templatised User defined Types(classes)
When we define
template <typename t="">
MyClass
{
T _member;
};
It is a class template. And when you instantiate it as
MyClass<int> or MyClass<float> then ultimately you will be getting two different classes.
Aswin Waiba
16-Aug-13 8:24am
View
when you instantiate a class template. we do have a definition. And when they are in the same file as in ur eg.
vector<int> intVec1;
vector<int> intVec2;
then the vector<int> will be instantiated only once. The second time the compiler encounters vector<int> it uses the already instantiated copy. But when the class template is instantiated on two different Files, we have two different objects containing definition of vector<int> class.
Aswin Waiba
16-Aug-13 8:00am
View
Please see below for further clarification
Aswin Waiba
16-Aug-13 8:00am
View
when u instantiate a template class. we will have an class vector<int> in MyFile1.obj. and we will have the same class vector<int> in MyFile2.obj. Now the question is since we have two definitions of the same class, why doesn't it give redefinition error during the linking phase. But since we doesn't, I would like to know how and why.
Aswin Waiba
16-Aug-13 5:42am
View
linking the two files to make an executable.
Aswin Waiba
20-Dec-12 9:44am
View
Sorry for the late reply. You could try simplyfying your code by copying data instead of rearranging the links, which can get a bit tricky.
void SortList()
{
if( NULL == head || NULL ==head )
cout<<"Linked list is empty or contains only one element"<<endl;
node *counter1, *counter2;
counter2 = head->next;
for(counter1 = head; counter1!=NULL ; counter1=counter2->next)
{
for(counter2 =counter1->next; counter2!=NULL; counter2=counter2->next)
{
compare(counter1,counter2);
}
}
}
void compare(node *counter1,node *counter2)
{
char tempName[10];
int tempMark;
if(counter2->mark > counter1->mark)
{
tempMark = counter2->mark;
strcpy(tempName, counter2->Name)
counter2->mark = counter1->mark;
strcpy(counter2->mark,counter1->mark);
counter1->mark = tempMark;
strcpy(counter1->Name, tempName);
}
}
Just another suggestion. Try using local variables. It makes the code much simpler to read and understand and stops the problem of phantom amends to variables. I hope this helps
Aswin Waiba
20-Dec-12 9:23am
View
Will your variable only have whole numbers or would you expect real numbers too. Because the code would be different in these cases.
Aswin Waiba
20-Dec-12 9:16am
View
Don't really know how it is done but would suggest using streams(input and output streams). And also have a look at producer consumer problem. That should clear up your doubts. And to solve that you could use mutex or more appropriate in your case semaphores for access control to shared memory resource.
Also one way of going about it. Correct me if I am wrong. You could have three buffers. One Input Buffer, One main buffer, one for output. The shared buffer being the main buffer. You could add contents to the Inputbuffer as it comes. And read from output buffer as you need.
You would add contents from Input buffer to Main Buffer, and From Main Buffer to output buffer in a round robin pattern.
I am not sure whether this will be helpful. You decide.
Aswin Waiba
20-Dec-12 9:00am
View
Deleted
Try.
int a()
{
printf("\nHello World\n");
return 1; //or 0 your call
}
Your program should work. And remember when working with function pointers:
typedef int (*foo)();
| | |
return type| parameters
typename
so for your original function void a(); it should have been
typedef void (*foo)();
foo fnptr=&a; //& not required
but since you are checking for a value inside if statement while calling the function. You probably wanted a function that returned some value.
Since your original function is void the if condition will always be false and the else part will be executed.
A better way to go about this would be:
int a(int param)
{
printf("Hello World\n");
return param;
}
int main()
{
typedef int (*Fun_Ptr)(int);
Fun_Ptr funPtr=&a;
int aNumber;
printf("\nEnter a number :");
scanf("%d",&aNumber);
if(50>funPtr(aNumber))
printf("\nOMG!!This is working");
else
printf("\nThis was supposed to work");
}
Its really simple eg and we are doing something useless such as pass a parameter to the function and returning it back unchanged. You could perform some sort of opertion on it like modulo or some thing. Anyway the idea is to understand the syntax for declaring a function pointer properly and using it properly.
Though the compiler will allow you to run your code its not safe and this kind of behaviour in the code should be avoided to all best intents.
I hope this is Clear.
Aswin Waiba
6-Dec-12 1:04am
View
Try this
void setStringValue(string stringText)
{
if(stringText.length())
m_stringTest = stringText;
else
cout<<"error";
}
This should make it clear if you're passing a corrupted string.
Aswin Waiba
5-Dec-12 4:41am
View
You could always inherit like
class ClassName: public vector{
public:
using vector:operator&();
//and so on
};
Show More