c++ 에서 변수 초기화
프로그래밍 2012/05/12 14:12 |c++ 에서 변수 초기화를 괄호를 이용하여 다음과 같이 할 수 있다.
초기화 할 때만 되고, 일반적인 assign 문으로는 사용할 수 없다.
즉, 다음과 같은 문장은 에러다.
c++ 에서 변수 초기화를 괄호를 이용하여 다음과 같이 할 수 있다.
초기화 할 때만 되고, 일반적인 assign 문으로는 사용할 수 없다.
즉, 다음과 같은 문장은 에러다.
singleton pattern 이란 대략 평생 하나의 instance 만 만들겠다는 것.
대략 constructor 를 private 으로 두어 외부에서는 instance 를 생성하지 못 하게 하고,
하나의 경로로만 instance 를 받게 하는 방식이다.
이 코드의 예에서는 외부에서 Babo::getInstance() 함수를 통해서 클래스의 instance 를 받을 수 있다.
그런데, 보면 결국 이 클래스의 instance 의 scope 는 전역이 된다.
즉, 어디서건 접근을 막을 수가 없다. 이렇게 해도 문제가 없을까나 ...
싱글톤(Singleton)은 전역에서 하나의 인스턴스에 접근하기 위해 사용하는 모델입니다. 여러가지 방법이 있고 각각의 장단점이 있지만... 저는 그 중에 Meyers singleton 방식을 주로 사용합니다. 아..
요렇게 푸는 사람은?
int sum(int n)
{
if (n == 1)
return 1;
return n + sum(n-1);
}
printf("%d\n", sum(100));
혹은 이렇게 푸는 사람은?
template<int N> class num
{
private:
int sum;
public:
num()
{ sum = (1+N)*N/2; }
void print(void)
{ printf("%d\n", sum); }
};
num<100> sum;
sum.print();
뽑아주나?
그리고
문제가 "1부터 100까지 더하는 코드를 작성하시오."였다면 2번과 3번 다 오답.
문제가 "1부터 100까지 더한 결과를 출력하시오."였다면 전부 정답.
하지만 문제를 "1부터 n까지 더한 결과를 출력하시오."로 바꾼다면 더 적절할듯.
recursion 사용했다면 뽑을 수 있겠지만,
template 쓴 사람은 사상을 의심해 볼 거 같아요.
대졸자에게 이건 너무 쉬운 문제일까나 ...
100 말고 n 까지 더해서 결과 return 하는 함수 정도를 만들 게 하는 게 적절할 듯.
Set the default text size to the given value, interpreted as "scaled pixel" units. This size is adjusted based on the current density and user font size preference.
| size | The scaled pixel size. |
|---|
Set the default text size to a given unit and value. See TypedValue for the possible dimension units.
| unit | The desired dimension unit. |
|---|---|
| size | The desired size in the given units. |
참고 : 자바에서 vim 사용 하기 설정
http://kwon37xi.egloos.com/1643980
확인해 보니 맞네 vim에서 자바 사용하기.. ㅋㅋ
자바 개발자가 된 만큼 이제 우분투를 사용해 봄이 어떤가?
http://www.ubuntu.com/
http://www.ubuntu.or.kr/
우분투 virtualbox 로 사용하고 있긴 하죠 : )
메인으로 쓰긴 좀 거시기 하고 ...
2008년부터 사용 중 ㅋㅋ
Indicates whether network connectivity is possible. A network is unavailable when a persistent or semi-persistent condition prevents the possibility of connecting to that network. Examples include
true if the network is available, false otherwiseIndicates whether network connectivity exists and it is possible to establish connections and pass data.
true if network connectivity exists, false otherwise.3g 와 Wi-Fi 를 모두 끄면 netInfo 에 null 이 날라온다. 이거도 체크 해야 함.
boolean
1-bit. May take on the values true and false only.
true and false are defined constants of the language and are not the same as True and False, TRUE and FALSE, zero and nonzero, 1 and 0 or any other numeric value. Booleans may not be cast into any other type of variable nor may any other variable be cast into a boolean.
byte
1 signed byte (two's complement). Covers values from -128 to 127.
short
2 bytes, signed (two's complement), -32,768 to 32,767
int
4 bytes, signed (two's complement). -2,147,483,648 to 2,147,483,647. Like all numeric types ints may be cast into other numeric types (byte, short, long, float, double). When lossy casts are done (e.g. int to byte) the conversion is done modulo the length of the smaller type.
long
8 bytes signed (two's complement). Ranges from -9,223,372,036,854,775,808 to +9,223,372,036,854,775,807.
float
4 bytes, IEEE 754. Covers a range from 1.40129846432481707e-45 to 3.40282346638528860e+38 (positive or negative).
Like all numeric types floats may be cast into other numeric types (byte, short, long, int, double). When lossy casts to integer types are done (e.g. float to short) the fractional part is truncated and the conversion is done modulo the length of the smaller type.
double
char
2 bytes, unsigned, Unicode, 0 to 65,535
Chars are not the same as bytes, ints, shorts or Strings.
long 이 8 byte 였다니 ㅠㅠ
게다가 unsigned integer 타입은 존재하지 않고,
char 만이 unsigned 로 사용된다 -_-;;
요건 참고.
http://mindprod.com/jgloss/unsigned.html
댓글을 달아 주세요
이런게 가능했었군요... ㅎㅎ
클래스 초기화와 유사한 원리