什么是什么时候使用"新"来创建一个类的实例的好政策?我已经习惯了一段时间编程C++,但我仍然不确定何时才是这样做的最佳时机:
MyClass thing(param1, param2);
Run Code Online (Sandbox Code Playgroud)
对此:
MyClass* thing;
thing = new MyClass(param1, param2);
Run Code Online (Sandbox Code Playgroud)
有什么建议?
我strtok()在c中使用来解析csv字符串.首先我将它标记为只是找出有多少令牌,这样我就可以分配一个正确大小的字符串.然后我使用上次用于标记化的相同变量.每次我第二次这样做虽然它strtok(NULL, ",")返回,NULL即使还有更多的令牌需要解析.谁能告诉我我做错了什么?
char* tok;
int count = 0;
tok = strtok(buffer, ",");
while(tok != NULL) {
count++;
tok = strtok(NULL, ",");
}
//allocate array
tok = strtok(buffer, ",");
while(tok != NULL) {
//do other stuff
tok = strtok(NULL, ",");
}
Run Code Online (Sandbox Code Playgroud)
所以在第二个while循环中它总是在找到第一个标记后结束,即使有更多的标记.有人知道我做错了什么吗?
下面的代码将一个多维数据集放在(0,0,0),另一个放在(0,.5,.5),每个多维数据集的维度为(.5,.5,.5).我正在尝试旋转屏幕到达这样的视图
但我得到了这个观点
.而且,我意识到我的颜色向后倾斜.
无论如何,这是我的代码到目前为止:
import com.sun.j3d.utils.geometry.*;
import com.sun.j3d.utils.universe.*;
import javax.media.j3d.*;
import javax.vecmath.*;
public class Positioning {
private Color3f lightBlue;
private Color3f aquaGreen;
private Color3f white;
private Color3f teal;
private BranchGroup group;
private SimpleUniverse universe;
public Positioning() {
lightBlue = new Color3f(0.0f, 0.749019608f, 1.0f);
aquaGreen = new Color3f(0.439215686f, 0.858823529f, 0.576470588f);
white = new Color3f(1.0f, 1.0f, 1.0f);
teal = new Color3f(0.196078431f, 0.6f, 0.8f);
universe = new SimpleUniverse();
group = new BranchGroup();
addCube(0.5f, 0.5f, 0.5f, new Vector3f(0.0f, 0.0f, 0.0f), lightBlue);
addCube(0.5f, 0.5f, 0.5f, …Run Code Online (Sandbox Code Playgroud) 我已经尝试了所有经典的技巧,让我的网页重新渲染在dom中所做的更改但没有任何效果.我已经试过了
element.className = element.className;
Run Code Online (Sandbox Code Playgroud)
以及访问我改变的一部分dom,但这也不起作用.
这是我的代码.Onload正文调用queryDB,在html中有一个id为"plants"的段落.到目前为止,此代码仅适用于firefox 3和chrome.
var timeout = 5000; //get new plants every 5 seconds
function queryDB() {
responseDoc = getXMLFrom("ajax/getallplants.php");
paragraph = document.getElementById("plants");
table = document.createElement("table");
table.setAttribute("class", "viewTable");
//clean up the last query
cleanUpLastResult(paragraph);
//loop through the responseDoc and dynamically add plants
if(plantsFound(responseDoc)) {
for(i = 0; i < responseDoc.documentElement.childNodes.length; i++) {
currentChild = responseDoc.documentElement.childNodes[i];
row = document.createElement("tr");
//old way of printing where the whole sci name and common name was just text
/*paragraph.appendChild(document.createTextNode(responseDoc.documentElement.childNodes[i].firstChild.nodeValue));
paragraph.appendChild(document.createElement("br"));*/
//newer way …Run Code Online (Sandbox Code Playgroud) 在标题中我有这样的设置
namespace NS {
typedef enum { GOOD, BAD, UGLY }enum_thing;
class Thing {
void thing(enum_thing elem);
}
}
Run Code Online (Sandbox Code Playgroud)
当然还有另一个与该标题一起使用的cpp文件.然后我有一个包含main()的线程cpp文件.在这个cpp文件中,我使用该枚举传递给方法thing().
using namespace NS;
int main() {
Thing t();
t.thing(BAD);
}
Run Code Online (Sandbox Code Playgroud)
当然,我从G ++那里得到其他错误,说没有声明BAD.有关如何克服此错误的任何帮助?