nitin1 15 Master Poster

Basically, I checked the project properties of the Component and it's as a dll. I tried to add msclr/mashal.h but it gives me error:

WinRT does not support #using of a managed assembly

It's because by adding the above .h, it uses few #using which seems not supported.

any thoughts on this? FYI, I am developing on UWP application.

Can you please give an example on how it works? A code snippet will do the job for me.

Thanks.

nitin1 15 Master Poster

Not projects. Basically I have one solution & in that I have a c++ library integrated as a submodule for image rendering etc. & my cs side code which is UI and other things. I have 10-11 submodules in the app & c++ library is one of them.

App (cs code, c#, UI) --> Cpp Library (c++ code)

Need to:

string (cs) --> const char * (cpp) & same in back direction as well.

I hope it clears the issue. Let me know if more info is needed.

Thanks.

nitin1 15 Master Poster

Actually, I have an UWP application having one solution in which I have cs & c++ modules. I need to pass a cs based string to cpp side & vice-versa.

I don't understand if we have dll involved here.

Please give your inputs.

nitin1 15 Master Poster

Hi,

How can I pass a c# string to C++ side of the app?

Right now, I have all handling in Const char format . When I pass c# string, c++ working fine when using Platform::String . But there is no good way of converting Platform::String to const char .

Any inputs from your side?

Any help will be appreciated.

Thanks.

nitin1 15 Master Poster

@Deceptikon

Awesome explanation. +1. Got the complete point. But, just one more question from your point only. Can you explain this little more?

The enclosing expression is your initialization statement for returnValue, which is why you can call c_str successfully (ie. the temporary object still exists)

So, calling c_str() is perfectly fine? if temporary object won't exist after enclosing braces of fun(), then callingc_str() should also be wrong. Isn't it?

Secondly, when exactly the temporray object be destroyed? I want to understand so that I can know what all operations I can do with the any object any function is returning.

Thanks in advance.

nitin1 15 Master Poster

@deceptikon Thanks a lot for the great explanation.

One question: when fun() returns, it calls the copy constructor again, right? As told here: Click Here

I got the point when you said it is temporary object but I need to understand the WHY part in this. In the fun(). string abc is a local which would be destructed after it returns from the function. I agree.

But, won't it call the copy constructor and then make the copy of the object and return it to the returnValue variable?

Please make me correct.

nitin1 15 Master Poster

@tinstaffl Can you please explain the reason behind this? I am curious to know why compiler might be doing this? Please throw some light on this.

nitin1 15 Master Poster

Hi,

I am facing an issue in string to const char pointer conversion. I am doing stuff in the fun() but here i am just giving my example. Here it the code:

// Helper function
string fun() {
   string abc = "Daniweb";
   // print here  #1
   return abc;
}

// main function
int main() {
   const char * returnValue = fun().c_str();
   // print here #2
   string returnValue2 = fun().c_str();
   // print here  #3
}

When I print the value in fun() function before returning it, it is printing fine. (#1)
When I print the value after const char (#2), it i giving some random values (sometimes empty, adding some characters at the end etc.).
When I print the value after returnValue2, it is working fine in all cases. (#3)

What's the problem with the case #2? Can't we do the way I have done in #2? Please explain.

Thanks in advance.

nitin1 15 Master Poster

Hi guys,
Here is the question:
I have Activity A, Activity B. Now, A --> B . Now, pressed the home button. Now, go to any image & "open with" will show my app. when pressing my app as the option, it will hit Activity A. When it will hit A, intent is handled in this activity.
At this stage, A & B are already in the stack. I want to discard all the activities except A. I have done it by restarting the activity using CLEAR_TASK intent (basically a restarter). But problem comes when my app was not opened initially (means no A or B in the stack), in that case when user goes to any image and do "open with", it will still restart the activity & it is not looking with user prespective because it will swap 2 activity when you see it.
How can we discard all the activities in android app keeping the current activity intact? Is there any way? LMK if you need more info.

Thanks.

nitin1 15 Master Poster

Hi everyone,

How are you? Starting some thread after long time :)

Actually, I have a group of 25 people. I have 20-25 mobile devices in my group. So, I have assigned 1-2 device on each person's name(as an owner). But, people in the group ask each other for the device for some help and promise to return it too. They may need specific device for some work which is a genuine thing. But, they forget to return it & person who gave has to ask on emails or each person where his/her device is.

Problem:
Asking on emails is very cumbersome. It is a like a spam everyday. people are asking where my XYZ device, if someone has please return etc.
Also, it delays the work which the person has to do using that device.
Also, it gives birth to a frusrattion too which is not good for a group.

What I want:
There should be some mechanism in which we have a list of all the devices & the curent person name with whom that device is right now.

possible solutions:

  • Have an excel sheet which the person who takes the device should update. No! People don't take that much pain.
  • Have an excel sheet & person who is giving the device should update. No! it will be too much work for him/her. Everyone is asking for some device & updating like this will be an overhead for the complete …
nitin1 15 Master Poster

Hi,

I have one function (in a library I can't change the code) which takes a key and returns a Object. This code is written in java. I am calling this function from cpp code. I am accepting the result as jobject.

  1. Added key as "key1" & value as boolean true by calling a function. it saves in a map after converting in into java BooleanObject.
  2. When I get it back I get it back as Object. I want to compare it with true now. How can I do that?

    Thanks in advance.

nitin1 15 Master Poster

Hi,

I have been working on JNI. I have one doubt. When I call any native method from android activity (Java code), then we get jclass object from jobject instance we get in the native method as a parameter. Why do we need it actually?

Here is a snippet from one website:

JNIEXPORT void JNICALL Java_TestJNIInstanceVariable_modifyInstanceVariable
          (JNIEnv *env, jobject thisObj) {
   // Get a reference to this object's class
   jclass thisClass = (*env)->GetObjectClass(env, thisObj);

   // int
   // Get the Field ID of the instance variables "number"
   jfieldID fidNumber = (*env)->GetFieldID(env, thisClass, "number", "I");
   if (NULL == fidNumber) return;

   // Get the int given the Field ID
   jint number = (*env)->GetIntField(env, thisObj, fidNumber);
   printf("In C, the int is %d\n", number);

   // Change the variable
   number = 99;
   (*env)->SetIntField(env, thisObj, fidNumber, number);

We got jclass from getObjectclass method.

  1. We used "thisClass" for fieldID.
  2. We used thisObj while getting the variable value (int).

When should we use what? What's the role of getting jclass obj reference? Can you please clear this thing? Thanks in advance.

nitin1 15 Master Poster

My issue exist on all browsers of tablets & mobiles. but working fine on desktop browsers.

nitin1 15 Master Poster

Hi,

I have one CSS.

.buttonSize
{
    min-width : 58%
}

Actually, I have two buttons, with text "Hovers" & "Copy". My button without any css taking spaces which can wrap the text size. This way size of two buttons is not same.

What I tried:
a) I have hacked by adding two spaces to "copy" and tried. On some browsers, it worked fine but on mozilla it was taking little more space(as compared to hovers button).
b) I have added the css class above & added in the tags of the buttons. worked fine on all browsers on all OS(windows, Ios, etc.) but when I tried it on tabs or mobiles, it was behaving as if no css class is defined and it is just wrapping the no. of characters.

Can you please tell me some way where I can be very sure & can make code totally browser in-dependent & os independent?

Thanks in advance.

nitin1 15 Master Poster

Hey,

I have been reading Java oracle tutorials. I read this thing.

Suppose, for example, class MsLunch has two instance fields, c1 and c2, that are never used together. All updates of these fields must be synchronized, but there's no reason to prevent an update of c1 from being interleaved with an update of c2 — and doing so reduces concurrency by creating unnecessary blocking. Instead of using synchronized methods or otherwise using the lock associated with this, we create two objects solely to provide locks.

public class MsLunch {
    private long c1 = 0;
    private long c2 = 0;
    private Object lock1 = new Object();
    private Object lock2 = new Object();

    public void inc1() {
        synchronized(lock1) {
            c1++;
        }
    }

    public void inc2() {
        synchronized(lock2) {
            c2++;
        }
    }
}

Use this idiom with extreme care. You must be absolutely sure that it really is safe to interleave access of the affected fields

Question: Can you please tell what exactly we pass in syncronized parameter. Why do we pass "this" usually? Also, how is "lock1" variable doing stuff for this example? Passing "this" only makes it object level locking? Please clarify this thing confusing me.
Thanks in advance.

nitin1 15 Master Poster

@freshly, As I checked, we don't have much things for threading in the book you mentioned. did you mean something else?

Thanks in advance.

nitin1 15 Master Poster

Hi all,

Actually, this question is not related to some coding or logic from my project. But, as I am doing hard and harder projects (acc. to me & my exp.), I am focussing more on design part of my projects. When I present my design to team members for the feature I have started working to get sign-off from the team, what things I should keep in my mind?

Can we have this thread helpful to every developer by jotting down things we should keep in mind for succesful execution of a design phase? As we have highly experienced people here, they can share how to approach a design of any feature. ** What should we include in HLD & in LLD? **

I am majorly concerned about the phases before the implementation phase like requirement gathering, design (LLD, HLD) etc. I always create a wiki before the meeting with the flow diagrams & requirements for the feature & I lock them till the project completion. what is the exact difference in HLD & LLD? How should we present to the team members so that in less time, they should get about the feature aim, what I am going to change, impact, metrics etc.

Note: I know the definiton, difference which we read in our college software engineering books. If we can have practial, real - life experiences, that would really help. :)

Thanks in advance.

nitin1 15 Master Poster

Hi,

I am creating a form in jsp.

<form action="" method="post"> 
<input type="hidden" name="status_1" value="0" /> 
<input type="checkbox" id="status_1" name="status_1" value="1" />
<input type="hidden" name="status_2" value="0" /> 
<input type="checkbox" id="status_2" name="status_2" value="1" />
<input type="hidden" name="status_3" value="0" />
<input type="checkbox" id="status_3" name="status_3" value="1" />
<input type="submit" /> </form>

I was referring this link: http://stackoverflow.com/questions/19239536/how-get-value-for-unchecked-checkbox-in-checkbox-elements-when-form-posted

So, can you tell how this is priortized? I mean if I am marking chekcbox as checked, then how does it decide which value to take in the req parameter?

Also, is there any order dependent thing in this? if hidden input is written after the checkbox or before this?

Note: Although this answer is accepted, but it doesn't work for me if I place hidden input before checkbox. When I say not working means it was always taking hidden input value when I place hidden input before checkbox with same name.

Thanks in advance.

nitin1 15 Master Poster

Hey James,

The code we discussed about date is giving zero days.

Instant startInstant = myclassObj.getStartTime().tonstant() ;
Instant endInstant = myclassObj.getExpiredTime().toInstant();

long days = ChronoUnit.DAYS.between(startInstant, endInstant);

:(

nitin1 15 Master Poster

Thanks for your quick response.
Yes. By errors, I meant that they are not defined any more. This happened when I changed boolean to Boolean. I suspect this happens because of lombok.

nitin1 15 Master Poster

No. NOt object class. Consider it as like this:

MyClass myClass = new MyClass();

myClass.isInternal()
myClass.getProductGlobal()
nitin1 15 Master Poster

Hi,

I was using booleans earlier in my class.
--> isProductRestricted
--> internal
--> isProductGlobal

I am using lombok too. So putting @Data at the top of class too. But, now I changed these boolean to Boolean variable.
I got errors where ever Object.isInternal() was used. I am not getting how isInternal() was working initially. There is no function in my class too.

Also, I am able to access boolean isProductGlobal using Object.getProductGlobal() bit there is "is" also attached to the productGlobal name. Can you please explain this? How is it happening here?

Thanks in advance.

nitin1 15 Master Poster

Thanks James for the quick response.

Instant instant1 = date1.toInstant();
Instant instant2 = date2.toInstant();

return ChronoUnit.DAYS.between(instant1,instant2);

Seems good?

Also, can you point out possible things in the code snippet I provided in my last comment? That will improve my understanding.

nitin1 15 Master Poster

HI james,

Thanks for the response.

But I have two Date object. I have to use Date date1 , Date date2. Now, I want to find days between them. Can we incorporate Date datatype?

Also, It is correct?

long diff = date2.getTime() - date1.getTime();
return TimeUnit.DAYS.convert(diff, TimeUnit.MILLISECONDS);

Basically, I want to get rid of leap year problem, day-light saving time thing etc. So, can you please suggest now?

nitin1 15 Master Poster

Hi,

I am stuck with a problem. I have two Date objects (util class objects). I want the difference between these two dates as the number of days between them? I am using Java 8. Can you please help me with this? Searched the web a lot. Some are saying to use Joda, while some are using TimeUnit. Some says Timeunit not handles leap year properly etc. I am confused now. Here is the link I read: http://stackoverflow.com/questions/20165564/calculating-days-between-two-dates-with-in-java

Thanks in advance.

nitin1 15 Master Poster

Hi,

Thanks for the response, James. No. I have to call getItem() method of ClassA class like this:

classAObj.companyMethod()

I will call company method as ClassA is inherited class of Company class. So, now, company method will call this.item.itemMethod() function. correct? Here comes the point of attraction: I want to call getName() method in itemMethod() method of class Item. I hope I am more clear this time. :)

Main point is: I want to call methods of ClassA class from class item class methods. Like item class obj is there in company class & company class is parent class of ClassA, ClassB etc. I have to take reference of ClassA somehow in functions of item class & then call it.

So, getName() is overriden in classA , ClassB etc so based on the value this fuction will return I have to do some logic in itemMethod() method. I must know who called this item clas obj (it is classA obj or classB or something else).

Thanks in advance.

nitin1 15 Master Poster

@James It doesn't talk about collections, threading etc.

@Freshly, I tried to search pdf for second book but not able to find it somewhere.

Thanks for the valuable responses.

nitin1 15 Master Poster

Hey,

I have one class Company and one Item class which is an object in Company class as shown:

public abstract class Company {

    @Inject
    private ItemClass item;

    void companyMethod() {
           this.item.itemMethod();
    }
}

public class ItemClass {
    public void itemMethod() {
       // logic
    }
}

So, many class inherits the Company abstract class say ClassA, ClassB, ClassC. So,

public class ClassA extends CompanyClass {

    void ClassAMethod() {
    }

    String getName() {
        //logic
    }
}

So, now when I declare a variable of ClassA say: classAObj . I called:

classAObj.companyMethod()

Now, I want to call ClassA's getName function in ItemMethod() of item class. Can i use this somehow? I need to call getName() there and take string value from this function? Using this or similar somehow?

Thanks in advance.

nitin1 15 Master Poster

Hey,

I have visited Daniweb after few months. I have seen "API" options in my profile. How can we use it? Is it similar to fb apis, twitter apis?

Thanks.

nitin1 15 Master Poster

Hi,

I have been working in Java for more than 8-9 months now. I want to have deep understanding of Java concepts now. For ex: Collections properties, threading, interfaces detailed concepts etc. I mean I have been using all these things for a while now but want to know about the things of Java in detail. Can you suggest some online source/Java book or something like this which I can follow? Usually, I search on web whatever I want to study and read the top 3-4 links. But, some book or course will help me better. Thanks in advance.

nitin1 15 Master Poster
public class MainActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ParseObject.registerSubclass(MyFirstClass.class);
        Parse.initialize(this, "Id", "Id");

        Button button = (Button)findViewById(R.id.button1);
        button.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                    callSearch();
            }
        });

        ParseUser user = new ParseUser();
        user.setUsername("username");
        user.setPassword("password");

        /*user.signUpInBackground(new SignUpCallback() {

            @Override
            public void done(ParseException arg0) {
                // TODO Auto-generated method stub
                Toast.makeText(MainActivity.this, "signed in", Toast.LENGTH_LONG).show();
            }
        });*/

        try {
            Thread.sleep(5000);
        } catch (InterruptedException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        MyFirstClass object = new MyFirstClass();
        object.add("one", "1000");
        object.add("two", "22");
        object.saveInBackground();

        Toast.makeText(this, "saved in server", Toast.LENGTH_SHORT).show();

        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }


    protected void callSearch() {
         ParseQuery<MyFirstClass> query = MyFirstClass.getQuery();
         query.whereEqualTo("one", "1000");
         query.findInBackground(new FindCallback<MyFirstClass>() {

            @Override
            public void done(List<MyFirstClass> arg0, ParseException arg1) {
                if(arg0 ==null || arg0.isEmpty()) {
                    Toast.makeText(MainActivity.this,"  <-- hi this is the string. " ,Toast.LENGTH_LONG).show();
                } else {
                    for(MyFirstClass myFirstClass : arg0) {
                        int str = myFirstClass.getInt("two");
                        System.out.print(str);
                    Toast.makeText(MainActivity.this, "not null " + str + " " + arg0.size() + " " + myFirstClass.getString("one") + " " + myFirstClass.getObjectId() + " " + myFirstClass.getOne() + " " + myFirstClass.toString(), Toast.LENGTH_LONG).show();
                    break;
                    }
                }

            }
        })  ;   
    }

I m using parse here. I am able to get the list size correctly in callSearch() function. But when I retrieving the values for the fields like one, two. they are coming as null. Can someone help me in this?
Class Name: MyFirstClass
Fields: one, two (both strings)
Thanks in advance.

nitin1 15 Master Poster

I have read few articles on google but I am still confused when to use what. I have come across checked and unchecked exceptions. I have one exception which I need to define. Let say, when xyz is null, I need to throw the inconsistentcyException which I will catch in the same file and that catch() block will throw one exception which extends runtime exception. This exception which I am defining newly would be used in this file only.

try{
   if(xyz == null) {
       throw new InconsistentException();
   }
   catch(InconsistentException e)
       throw new AlreadyExisitingExceptionExtendingRuntimeException();
   }
}

I need to define the class having Inconsistent Exception. This snippet is written in execute() function and call() function is calling it which is catching the AlreadyExisitingExceptionExtendingRuntimeException(). I don't know which exception to use(runtime or exception). Please explain. I read the SO links but confused. Can you please explain with an example? :) Thanks in advance.

nitin1 15 Master Poster

Hi,

Actually, I want to make one Singleton class which will create one instance for one thread. I mean if we have 10 threads, then Singleton will create only one object for one thread. IF same thread will ask for one more instance it will return the same instance. Basically, my singeton is not process-specific, it would be thread-specific. Please tell how I can think for this modification of Singleton. I don't want the code but I need the idea how to proceed for the same. May be links or snippets will help. Thanks in advance.

nitin1 15 Master Poster

I built one Sync code. I am using eclipse for the same. Actually my code is working fine in eclipse. But when I run it in Tizen OS device. I am using beecrypt library for the same. I have one line

auto_ptr<Mac>(Mac::getInstance("HmacSHA256"));

Actually, it is throwing exception on this line. I have installed beecrypt in Phone, then ran the Sync code but it is saying (exception message)

HmacSHA256 not Available

What can be the problem? I am using:

  • C++
  • beecrypt library
  • Eclipse Juno
  • Ubuntu 12.04

Both sync code and beecrypt are built properly. Sync code is working fine on eclipse but when porting on Tizen OS (Mark it - exactly the same CODE). It is throwing exception. which I wrote above only. What can be the possible error? Can it be the linking error? Please Help. Any help would be appreciated.

nitin1 15 Master Poster

Nice explanation boss. Then, why do we do it this way? I mean :

new BufferedReader(new InputStreamReader(input));

why we make the inputStreamReader first? I want to know in deph little bit. What is the significance of InputStreamReader in this case?

nitin1 15 Master Poster

If I will remove that thread, then at the same time if server sends data, will it work? I mean at the time when actionlistner is sending data to server , then server sends some data. then will it wait for the action listener to complete or will it go side-by-side?

nitin1 15 Master Poster

So, when should I use ByteArrayInputStream? I am confused little bit. I have used this also. But don't know when to use it specifically? Can you provide one case where this will be useful? I mean I want to get the essence of this class.

nitin1 15 Master Poster

I have made very simple code to larn the functionality.

String str = "ABC";
        InputStream input = new ByteArrayInputStream(str.getBytes());

        BufferedReader reader = new BufferedReader(new InputStreamReader(input));
        System.out.println(Character.valueOf((char) reader.read()));
        System.out.println(reader.read());
        System.out.println(reader.read());
        System.out.print(reader.read());

Secondly this one,

String str = "ABC";
        InputStream input = new ByteArrayInputStream(str.getBytes("UTF-8"));

        System.out.print(input.read());
        System.out.print(input.read());
    }

output is same for the ways. Which way is good, and when should I use the each one of them? Thanks.

nitin1 15 Master Poster
public class Input {

    static InputStream reader = null;
    /**
     * @param args
     * @throws IOException
     * @throws InterruptedException 
     */
    public static void main(String[] args) throws IOException, InterruptedException {

        Test test = new Test();
        test.start();
        String str = "1 21";
    //  Scanner scan = new Scanner(System.in);
        try {
            reader = new ByteArrayInputStream(str.getBytes("UTF-8"));
            System.setIn(reader);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }

    }

}

class Test extends Thread {

    public void run() {
        super.run();
        try {
            getSum();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    private void getSum() throws InterruptedException {

        Scanner scan = new Scanner(System.in);
        int x = scan.nextInt();

        int y = scan.nextInt();
        System.out.println(x + y);

        scan.close();
        this.interrupt();
    }

}

When I am uncommeting the line, then it is throwing exception. Main thread Exception. Can you please explain why it is so? Thanks in advance.

nitin1 15 Master Poster

But, I want to take input from the ActionListeners like when I click on the button I want to send one number to the server. But in CLient, I have SYstem.in as the stream to get input. But I am not using command line to take input now. I want some way to give input to CLient which is waiting for System.in right now. I want the code to make the thread waiting for my input from ActionListeners directly.

Currently, I made the code to take input from Command-line. But , I want to modify it so that when I click on any button, I will send one number to the thread waiting. How to do this?

nitin1 15 Master Poster

I have one project named P2PTicTac. I have one file named layout.java. and one with CLient.java. I have made simple GridView in layout file with 9 buttons in 3*3 Grid.

I have run two threads in client.java. One for reading the data from server and one for writing data to server. I have actionListeners in Layout file. When I click on any button in layout ,
then I want to send one number to server using the thread which I run in client.java. And then server will send me a number which I will use to update my GUI in layout.java.

I have made both the files completely but I don't know how to give data to the thread so that I could send to server and how to update GUI when I get response from server in write thread. I hope I am clear. I know thread is a separate entity. But How can I do my task? I don't want code. I want logic how to do this thing?

P.S I have used AWT for making the GUI and I used simple THREAD API of Java to run two threads in the CLient.java class.

CLient.Java

sReadThread = new Thread(new Runnable() {

                @Override
                public void run() {
                    Scanner scanner = new Scanner(System.in);
                    System.out.println(describeUserCommands());
                    while (true) {
//                      System.out.println("User: ");
                        String userInput = scanner.nextLine();
                        if (userInput.equalsIgnoreCase("help"))
                            System.out.println(describeUserCommands());
                        else if (userInput.startsWith("bye")) {
                            break;
                        } else {
                            cOut.println(userInput);
                            //System.out.println("Command sent: " + userInput);
                        }
                    }
                    try {
                        scanner.close();
                        System.out.println("User closed …
nitin1 15 Master Poster

I read about cherry-picking. It says: You have one branch x1 and branch x2. You want to take one commit from many commits of x2 and want to merge it with x1. You have 4-5 commits in x1 and now you take one commit or range of them and want to merge it with x2. It is cherry-picking. We can do using:

git cherry-pick ID

Is this correct what I got about cherry-picking?

Secondly, It says: you have some consequences when you cherry-pick the commits.

This changing of commit IDs breaks git's merging functionality among other things (though if used sparingly there are heuristics that will paper over this). More importantly though, it ignores functional dependencies - if C actually used a function defined in B, you'll never know.

I didn't get this thing about the effects of cherry-picking. Can anyone explain this? Any help would be aprreciated. Thanks.

nitin1 15 Master Poster

Thanks Sepp2k. But what is valid dynamic_cast then in case of downcast? Can you tell this thing?

Secondly, Can you explain this line?

You can use dynamic_cast when the castee is a pointer or reference to a class that contains at least one virtual member (that's what's meant by the pointer being polymorphic)

nitin1 15 Master Poster

@sepp2k

Class A is a base class. Class B is derived.

Base b;
    Derived d;

    Base *pb = dynamic_cast<Base*>(&d);          
    Derived *pd = dynamic_cast<Derived*>(&b); 

And, this one. Employee is base class.

Employee employee;
    Programmer programmer;

    // upcast - implicit upcast allowed
    Employee *pEmp = &programmer;

    // downcast - explicit type cast required
    Programmer *pProg = (Programmer *)&employee;

What is the difference between this thing now?

Please explain: why do we need to have base class' at least one virtual function? Why is it so?

Thanks.

nitin1 15 Master Poster

I read many articles on Web regarding this. I am able to understand what static_cast does. I am not to properly understand why, and when we have to dynamic cast. There is
something "we can downcast the pointer when it is polymorphic". I am not able to understand what they meant by this. Can anyone please explain with one good example?

In short, Use of static cast and dynamic cast? Any help would be appreciated. Thanks in advance.

nitin1 15 Master Poster

@sepp2tk nice explanation. Can you tell me onw thing why we have to commit? The file in which i am making changes is in local repository. right? I read somewhere that workspace is different from the local repository. How? I mean when I made changes in testfile1.txt. it is in a folder. Isn't it my local repo only?

What is need of committing? I know there is one .git hidden folder. I checked into that. There is no copy of testfile1.txt present. When I do Ctrl + S, then it is saving my file. So what is committing? Do I have two copies of the same file in git system?(one i am editing and one i over-write after commoting) ? Explain.

nitin1 15 Master Poster

Hi,

I am learning Git system these days. I have made a new folder in ubuntu and in terminal did this:

  1. git init
  2. then made a file testfile1.txt
  3. then made a branch using "git branch newbranch"
  4. then checkout to this branch.
  5. then, made a new file in the branch testfile2.txt and added some content.
  6. then i switched to master branch.
  7. then "ls". there also I was able to see this file. (BIG DOUBT, why I saw this file in master branch.)
  8. Then I switched again to newbranch and "git add ." --> "git commit" then again i switched to the master branch and then "ls".
  9. Now, I was not able to see testfile2.txt but obviously it was there in newbranch.

Can you help me visualize that why I was able to see the file till I didn't commit the file? Please help.

nitin1 15 Master Poster

@James Then, what about Static functions? How will you explain that thing? We can give definition inside? Please correct me.

nitin1 15 Master Poster

@rubberman Ya that's fine. This is a rule I got it. But, don't we have reason for this? I mean global variables by default set to zero or NULL. Am I right ? Please correct me.

nitin1 15 Master Poster

Thanks Moschops. But I am declaring it in the class right? Why do I need to create it outside? Please elaborate more. http://www.tutorialspoint.com/cplusplus/cpp_static_members.htm
Here, they are saying that by dafault, it will be zero if not other value in present. Please check.

So, like that all Static members have to be initialized in this way? Are you telling this thing?