I have a class definition of the form
class X
{
public:
//class functions
private:
A_type *A;
//other class variables
};
and struct A_type is defined as
struct A_type
{
string s1,s2,s3;
};
Inside the constructor, I allocate appropriate memory for A and try A[0].s1="somestring";
It shows segmentation fault.
Is this kind of declaration invalid, or am I missing something
Let's say I have a background worker like this:
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
while(true)
{
//Kill zombies
}
}
How can I make this background worker start and stop using a button on a WinForm?
I mean, won;t it be more specific and appropriate if i "only" keep "protected","internal" and "private" members (field,method,property,event) in a class which is declared as "internal" ?
I have seen this practice ( having "public" members in an "internal" class) in various code so just wanted to know is it a bad practice or does it has some benefit or advantage.
[Only concerned about C#]
Thanks for your interest.
say suppose I have class as :
public class Age {
private int age;
public int getAge() {
return this.age;
}
}
In my Main class I am calling the getAge() method many times.
So I wanted to know is it advisable to call so many times or call once and assign it to some variable and use that variable.
Which is best and why?
So after a few hours of workaround the limitation of Reflection being currently disabled on the Google App Engine, I was wondering if someone could help me understand why object reflection can be a threat. Is it because I can inspect the private variables of a class or are there any other deeper reasons?
I'm doing a code review and I noticed such a code:
@Entity
@Table(name = "SOME_TABLE")
public class SomeReportClass {
@Column(name = "REPORT_NUMBER", length = 6, nullable = false)
private String reportNumber;
.....
public String getReportNumber() {
return reportNumber;
}
public void setReportNumber(String reportNumber) {
this.reportNumber = StringUtils.trimToNull(reportNumber);
}
}
Every time I see trimming inside of a setter I feel that its not the clearest solution - what is the general practice with that issue?
Not real information:
$ ssh-keygen -t rsa -C "[email protected]"
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/Tekkub/.ssh/id_rsa):
ssh.txt
I entered a file name here. Not sure if i should have,
Enter passphrase (empty for no passphrase):
I am stuck here. I type and it doesnt work
i have a STL string member variable in my class,
class A {
public:
const char* getData1() const { return data.c_str());
const string& getData2() const { return _data; }
private:
string _data;
};
getData1() vs. getData2(), which one is better?
Here are what I think are the relevant parts of the code of these two classes. First, TreePointer (original source here):
public abstract class TreePointer<T extends TreeNode>
implements Iterable<TokenResolver<T>>
{
//...
/**
* What this tree can see as a missing node (may be {@code null})
*/
private final T missing;
/**
* The list of token resolvers
*/
protected final List<TokenResolver<T>> tokenResolvers;
/**
* Main protected constructor
*
* <p>This constructor makes an immutable copy of the list it receives as
* an argument.</p>
*
* @param missing the representation of a missing node (may be null)
* @param tokenResolvers the list of reference token resolvers
*/
protected TreePointer(final T missing,
final List<TokenResolver<T>> tokenResolvers)
{
this.missing = missing;
this.tokenResolvers = ImmutableList.copyOf(tokenResolvers);
}
/**
* Alternate constructor
*
* <p>This is the same as calling {@link #TreePointer(TreeNode, List)} with
* {@code null} as the missing node.</p>
*
* @param tokenResolvers the list of token resolvers
*/
protected TreePointer(final List<TokenResolver<T>> tokenResolvers)
{
this(null, tokenResolvers);
}
//...
/**
* Tell whether this pointer is empty
*
* @return true if the reference token list is empty
*/
public final boolean isEmpty()
{
return tokenResolvers.isEmpty();
}
@Override
public final Iterator<TokenResolver<T>> iterator()
{
return tokenResolvers.iterator();
}
// .equals(), .hashCode(), .toString() follow
}
Then, JsonPointer, which contains this .parent() method which I'd like to factorize here (original source here:
public final class JsonPointer
extends TreePointer<JsonNode>
{
/**
* The empty JSON Pointer
*/
private static final JsonPointer EMPTY
= new JsonPointer(ImmutableList.<TokenResolver<JsonNode>>of());
/**
* Return an empty JSON Pointer
*
* @return an empty, statically allocated JSON Pointer
*/
public static JsonPointer empty()
{
return EMPTY;
}
//...
/**
* Return the immediate parent of this JSON Pointer
*
* <p>The parent of the empty pointer is itself.</p>
*
* @return a new JSON Pointer representing the parent of the current one
*/
public JsonPointer parent()
{
final int size = tokenResolvers.size();
return size <= 1 ? EMPTY
: new JsonPointer(tokenResolvers.subList(0, size - 1));
}
// ...
}
As mentioned in the subject, the problem I have here is with JsonPointer's .parent() method. In fact, the logic behind this method applies to TreeNode all the same, and therefore to its future implementations. Except that I have to use a constructor, and of course such a constructor is implementation dependent :/
Is there a way to make that .parent() method available to each and every implementation of TreeNode or is it just a pipe dream?
I have this but it always returns null
private static String getParameters(Method aMethod) {
Class<?>[] parameterTypes = aMethod.getParameterTypes();
for (Class<?> aParam : parameterTypes) {
System.out.print(aParam.getName());
}
return null;
}
For instance:
private final Object o;
public void doSomething(){
final Object local = this.o;
//access methods of local;
}
This practice is followed in lots of java classes (such as ArrayBlockingQueue). What's the benefit of this?
Hi Everyone
After a extensive debugging session I found that the problem was that I called the setter of a readonly property. Is there a trick to provoke a compiler warning when this happens? Because marking the setter private does not work.
Cheers,
CA
I mean, won;t it be more specific and appropriate if i "only" keep "protected","internal" and "private" members (field,method,property,event) in a class which is declared as "internal" ?
I have seen this practice ( having "public" members in an "internal" class) in various code so just wanted to know is it a bad practice or does it has some benefit or advantage.
[Only concerned about C#]
Thanks for your interest.
In the following code, when the ctor of X is called will the ctor of A or B be called first? Does the order in which they are placed in the body of the class control this? If somebody can provide a snippet of text from the C++ standard that talks about this issue, that would be perfect.
class A;
class B;
class X
{
private:
A a;
B b;
}
I have created an array of coordinates. The centre of an image should move through those coordinates. I have used TranslateAnimation to achieve it. But during the animation the image is moving within the last two coordinates.
Below is my code:
private void CreateAnimationAndRun() {
// move to the different coordinates one by one
for(int k=0; k
The above function is called on a button click.
private static void SaveOrRemove<T>(string key, T value)
{
if (value == null)
{
Console.WriteLine("Remove: " +key);
}
....
}
If I call passing 0 to value: SaveOrRemove("MyKey", 0), the condition (value == null) is false, then CLR dont make a (value == default(T)). What really happens?
i use a treeview to display files and folders like Windows Explorer. it has a NodeMouseClick event but sometimes when i click +, this event doesn't fire.
private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{
MessageBox.Show("node mouse click");
}
can anyone explain for me why ? and how to know whenever i click + ?
thanks in advance!
Hello,
I have a strange problem which I can't fix:
A field:
private boolean[][][] gaps;
Constructor (1st line):
gaps = new boolean[NOBARRICADES][WIDTH][HEIGHT];
Constructor (2nd line):
for (int i = 0; i < NOBARRICADES; i++) {
JAVA throws an error for the 2nd line, saying:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException
Does it have anything to do with JAVA syntax (the mistake is in these lines of code) or I should look for the problem somewhere else?
Hi,
I need a C# function that takes 2 strings as an input and return an array of all possible combinations of strings.
private string[] FunctionName (string string1, string string2)
{
//code
}
The strings input will be in the following format:
String1 eg - basement
String2 eg - **a*f**a
Now what I need is all combinations of possible strings using the characters in String2 (ignoring the * symbols), and keeping them in the same character position.
Eg: baaement, baaefent, baaefena, basefent, basemena, etc
any help? :)
HI there, I'm slightly new to programming, more of a hobby. I am wondering if a the following logic or technique has a specific name, or term. My current project has 7 check boxes, one for each day of the week. I needed an easy to save which boxes were checked.
The following is the method to saved the checked boxes to a single number. Each checkbox gets a value that is double from the last check box. When I want to find out which boxes are checked, I work backwards, and see how many times I can divide the total value by the checkbox value.
private int SetSelectedDays()
{
int selectedDays = 0;
selectedDays += (dayMon.Checked) ? 1 : 0;
selectedDays += (dayTue.Checked) ? 2 : 0;
selectedDays += (dayWed.Checked) ? 4 : 0;
selectedDays += (dayThu.Checked) ? 8 : 0;
selectedDays += (dayFri.Checked) ? 16 : 0;
selectedDays += (daySat.Checked) ? 32 : 0;
selectedDays += (daySun.Checked) ? 64 : 0;
return selectedDays;
}
private void SelectedDays(int n)
{
if ((n / 64 >= 1) & !(n / 64 >= 2))
{
n -= 64;
daySun.Checked = true;
}
if ((n / 32 >= 1) & !(n / 32 >= 2))
{
n -= 32;
daySat.Checked = true;
}
if ((n / 16 >= 1) & !(n / 16 >= 2))
{
n -= 16;
dayFri.Checked = true;
}
if ((n / 8 >= 1) & !(n / 8 >= 2))
{
n -= 8;
dayThu.Checked = true;
}
if ((n / 4 >= 1) & !(n / 4 >= 2))
{
n -= 4;
dayWed.Checked = true;
}
if ((n / 2 >= 1) & !(n / 2 >= 2))
{
n -= 2;
dayTue.Checked = true;
}
if ((n / 1 >= 1) & !(n / 1 >= 2))
{
n -= 1;
dayMon.Checked = true;
}
if (n > 0)
{
//log event
}
}
The method works well for what I need it for, however, if you do see another way of doing this, or a better way to writing, I would be interested in your suggestions.
hallo guys,
First, I have this function:
private var file:File = new File;
public function openBrowse():void{
file.browseForOpen("Objekt auswählen");
}
but how can I put the object to a datagrid?
Hello, I've missed and cloned read-only git from my repository. I've made changes and another stuff but, of course, can't upload changes. Can I do this? Reclone only private git or something like this but save changes logged in git.